Category Archives: Без рубрики

Java.Hibernate.Beginner.Why use HQL ? What benefits ?

✅ Why use HQL? What are its benefits? Answer:HQL (Hibernate Query Language) is designed to let you write object-oriented, database-independent queries over your mapped entities. Its main benefits are: 🔹 1) Works with entities, not tables✅ You write queries using … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.Why use HQL ? What benefits ?

Java.Hibernate.Beginner.How do you create a basic HQL query?

🔹 Step-by-step example: 🔹 Key points:✅ FROM User is an HQL statement selecting the entire User entity — no need for SELECT if you want the whole object.✅ session.createQuery(hql, User.class) creates a typed query returning List<User>.✅ Always execute inside an … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.How do you create a basic HQL query?

Java.Hibernate.Beginner.Do i need write select word or not ?

No — you don’t have to use SELECT in HQL if you want to fetch entire entities. In HQL, you can simply write: This is equivalent to: Hibernate understands both forms — when you omit SELECT, Hibernate implicitly selects the … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.Do i need write select word or not ?

Java.Hibernate.Beginner.What is HQL (Hibernate Query Language)?

HQL (Hibernate Query Language) is Hibernate’s object-oriented query language that lets you query your database using your Java entity and property names, rather than database table or column names. 🔹 Key points:✅ HQL is similar to SQL in syntax but … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What is HQL (Hibernate Query Language)?

Java.Hibernate.Beginner.What is the difference between load() and get() methods?

🔹 1️⃣ session.get()✅ Loads the entity immediately from the database or session cache.✅ Returns the real object, not a proxy.✅ Returns null if the entity with the given ID doesn’t exist — safe for optional lookups.✅ Eager behavior → triggers … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What is the difference between load() and get() methods?

Java.Hibernate.Beginner.How do you retrieve an object by its ID?

You retrieve an object by its primary key (ID) using either:1️⃣ session.get() — recommended for most use cases, or2️⃣ session.load() — advanced use cases. 🔹 Using session.get() Loads the entity immediately from the database or session cache. Returns the entity … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.How do you retrieve an object by its ID?

Java.Hibernate.Beginner.When object becomes unattached ?

An entity becomes detached (unattached) when it was persistent in a session but is no longer associated with any open session. This happens in several common scenarios: 🔹 1) Session is closed As soon as you call session.close(), all persistent … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.When object becomes unattached ?

Java.Hibernate.Beginner.How do you delete an object in Hibernate?

You delete an object in Hibernate by:1️⃣ Loading or attaching the entity you want to delete in an active session.2️⃣ Calling session.delete(entity) to mark it for deletion.3️⃣ Committing the transaction to execute the SQL DELETE. 🔹 Example of deleting a … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.How do you delete an object in Hibernate?

Java.Hibernate.Beginner.When i will get NonUniqueObjectException ? Give example

You get a NonUniqueObjectException if you try to reattach a detached entity using update(), but the session already has another persistent instance with the same identifier (primary key). 🔹 Why does it happen? Hibernate ensures that within a single session, … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.When i will get NonUniqueObjectException ? Give example

Java.Hibernate.Beginner.How do you update an object in Hibernate?

There are two main ways to update an object in Hibernate, depending on whether the object is still persistent or has become detached: 🔹 1) Updating a persistent object (easiest case) If the entity is still attached to an open … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.How do you update an object in Hibernate?