Hibernate object states by R4R Team

Hibernate defines and supports the following object states:

1. Transient - Transient instances will be destroyed by the garbage collector if the application does not hold a reference anymore. An object is transient if it has just been instantiated using the new operator, and it is not associated with a Hibernate Session. It has no persistent representation in the database and no identifier value has been assigned. Use the Hibernate Session to make an object persistent (and let Hibernate take care of the SQL statements that need to be executed for this transition).

2. Persistent - Developers do not execute manual UPDATE statements, or DELETE statements when an object should be made transient. A persistent instance has a representation in the database and an identifier value. It might just have been saved or loaded, it is by definition in the scope of a Session. Hibernate will detect any changes made to an object in persistent state and synchronize the state with the database when the unit of work completes. 

3. Detached - We call them application transactions, i.e., a unit of work from the point of view of the user. A detached instance is an object that has been persistent, but its Session has been closed. The reference to the object is still valid, of course, and the detached instance might even be modified in this state. A detached instance can be reattached to a new Session at a later point in time, making it (and all the modifications) persistent again. This feature enables a programming model for long running units of work that require user think-time. 
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!