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

Java.Hibernate.Beginner.What is better, save or persist ?

It depends on your needs — but in modern, portable code, persist() is usually the better choice. Here’s why: 🔹 Why prefer persist()✅ Standardized (JPA) — persist() is part of the JPA specification, so it’s portable across any JPA implementation … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What is better, save or persist ?

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

To save an object in Hibernate, you need to:1️⃣ Open a Hibernate Session.2️⃣ Start a transaction.3️⃣ Call session.save() or session.persist() to make the object persistent.4️⃣ Commit the transaction to write the object to the database.5️⃣ Close the session to release … Continue reading →

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

Java.Hibernate.Beginner.What happens if you don’t close a session in Hibernate?

✅ What happens if you don’t close a Hibernate session? Answer:If you don’t close a Session, several serious problems can occur: 🔹 1) Database connection leaks✅ Each Hibernate Session holds a JDBC connection (from your connection pool, e.g., HikariCP).✅ If … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What happens if you don’t close a session in Hibernate?

Java.Hibernate.Beginner.Explain “Can leave the entity in a transient state if there’s no transaction (e.g., changes may not actually persist)”

🔹 What happens technically:When you call session.save(entity), Hibernate assigns an identifier (e.g., the primary key) and puts the entity into the session’s first-level cache — so it becomes persistent in the session context. But if you haven’t started a transaction, … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.Explain “Can leave the entity in a transient state if there’s no transaction (e.g., changes may not actually persist)”

Java.Hibernate.Beginner.What is the difference between save() and persist() in Hibernate?

🔹 1) save()✅ Returns the generated identifier (primary key) immediately as a Serializable value.✅ Works both inside and outside of an active transaction.✅ Can leave the entity in a transient state if there’s no transaction (e.g., changes may not actually … Continue reading →

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

Java.Hibernate.Beginner.How do you begin and commit a transaction in Hibernate?

You manage transactions in Hibernate using the Transaction API. You: Begin a transaction with session.beginTransaction(). Commit it with transaction.commit(). Optionally roll it back with transaction.rollback() in case of errors. 🔹 Basic example of transaction management: 🔹 What happens during this … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.How do you begin and commit a transaction in Hibernate?

Java.Hibernate.Beginner.How do you close a Hibernate session?

You close a Hibernate Session by calling its close() method: 🔹 What happens when you call session.close()?✅ Releases the JDBC connection associated with the session back to the connection pool (e.g., HikariCP).✅ Destroys the session’s first-level cache, evicting all managed … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.How do you close a Hibernate session?

Java.Hibernate.Beginner.In which cases entity starts to be trackable ?

An entity starts being trackable (i.e., Hibernate will dirty-check it and sync changes) when it becomes persistent — specifically, when it’s associated with an open Hibernate session. 🔹 Here are the cases when an entity becomes persistent and trackable: ✅ … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.In which cases entity starts to be trackable ?

Java.Hibernate.Beginner.What is dirty checking ?

Dirty checking is Hibernate’s automatic mechanism that tracks changes to persistent entities and ensures that any updates you make to those objects are automatically synchronized to the database when the session is flushed (usually at transaction commit). 🔹 How does … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.What is dirty checking ?

Java.Hibernate.Beginner.Whats is Stateless session ?

A StatelessSession is a lighter, faster version of Session. It does not use first-level cache, doesn’t track entity states, or support automatic flushing. Best suited for batch processing where you just want to read or write data efficiently without overhead. … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Beginner.Whats is Stateless session ?