Hibernate - Difference between transient and detached objects

Explain the difference between transient (i.e. newly instantiated) and detached objects in hibernate.

- Transient objects do not have association with the databases and session objects. They are simple objects and not persisted to the database. Once the last reference is lost, that means the object itself is lost. And of course, garbage collected. The commits and rollbacks will have no effects on these objects. They can become into persistent objects through the save method calls of Session object.

- The detached object have corresponding entries in the database. These are persistent and not connected to the Session object. These objects have the synchronized data with the database when the session was closed. Since then, the change may be done in the database which makes this object stale. The detached object can be reattached after certain time to another object in order to become persistent again.

Explain the difference between transient (i.e. newly instantiated) and detached objects in hibernate.

Transient :In this state, an instance is not associated with any persistence context.

Detached :This is a state for an instance which was previously associated with a persistence context and has been currently closed.
Hibernate - Advantages and disadvantages of detached objects
Advantages and disadvantages of detached objects - Detached objects passing can be done across layers upto the presentation layer without using Data Transfer Objects. ...
Hibernate - What is Hibernate Query Language (HQL)?
What is Hibernate Query Language (HQL)? - Hibernate Query Language is designed for data management using Hibernate technology...
Hibernate - Flow of Hibernate communication with RDBMS.
Flow of Hibernate communication with RDBMS - The Hibernate configuration is to be loaded and creation of configuration object is done. The mapping of all hbm files will be performed automatically...
Post your comment