Hibernate Entities Life cycle
The entities managed by Hibernate has a life cycle associated with them. Either you can make a new object in heap and save it into database or the data can be fetched from the database and given to user as database. The hibernate objects go through certain stages in the life cycle. Only entity objects participate in the life cycle. The value objects do not participate in the life cycle. The stages in the life cycle of an entity managed by Hibernate are as follows:Transient Objects
When objects are created in the Java layer with new or similar operator and they have no corresponding record existing in database than these objects are termed as Transient objects. These objects exist in heap. The primary key attribute of this object is still not set. Transient objects are non transactional and in fact Hibernate has no knowledge of these objects at this point of time, Objects that are referenced only by other transient instances are, by default also transient. For an instance to transition from transient to persistent state or to go managed state, it requires either a call to persistence manger or the creation of a reference from an already persistent instance.
Persistent Objects
Persistent entity is again an object in heap but it has a valid database identity associate with it.
The entity goes into persistent object by one of following means:
- Objects instantiated by application and then made persistent by calling one of the methods on the persistent manager.
- The objects become persistent when a reference is created from one of the persistent object.
- The entities retrieved from the database either by doing query, lookup or navigating the object graph.http://www.oyejava.com/tiki-editpage.php?page=Hibernate%20Entities%20Life%20cycle
Removed Object
An object scheduled for deletion either by calling delete or because of orphan deletion of entities. One should not use the object in Java layer as the database record will be deleted at the end of session. A logic build around these objects might get into trouble.
Detached Object
The object in persistent state go into detached state after the persistent context is closed.
Detached objects can be brought into other persistent context by reattachment or merging. Detached object still has a valid primary key attribute but it is no longer managed by Hibernate.
Back to Hibernate Index
Back To Java Home
Back To Home
Sidebar
Last wiki comments
- Introduction to ORM: ugg boots
- Introduction to ORM: ugg boots
- AOP: Thanks
- Lalit Bhatt: Superb Collection
- Lalit Bhatt: J2EE training
- Introduction to ORM: timberland shoes
- Introduction to ORM: jordan shoes
- Introduction to ORM: nike air max
- Pune Tourist Spots: KONARK PARK CLOSED
- jQuery Form Validations: Jquery Developer
Sidebar
Random Pages
- What markets work on?
- Why projects fail?
- Bharat Band - Jai ho
- The concept of Nation
- Don't hide complexity if it cannot be handled in a robustway
Last blog post comments
-
Prospective MLA for Pune election - 2009: ugg boots
Wed 01 of Sep., 2010 12:58 IST
-
Bharat Band - Jai ho: How do we protest?
Wed 18 of Aug., 2010 13:13 IST
-
Divided by Destiny: Contact
Fri 23 of July, 2010 16:02 IST
-
Future of Java: thesis writing
Sat 17 of July, 2010 01:50 IST
-
Hang till Death Mr. Kasab: some change
Mon 28 of June, 2010 16:03 IST
-
God Religion : Why we are confused?: Re: Is GOD Necessary?
Tue 15 of June, 2010 17:29 IST
-
God Religion : Why we are confused?: Is GOD Necessary?
Tue 15 of June, 2010 13:06 IST
-
The reason in religion: good
Wed 10 of Mar., 2010 18:30 IST
-
The confusion of Design Patterns: I think at macro level you are right...
Tue 23 of Feb., 2010 03:31 IST
-
The Indian Municipality: Comment
Fri 22 of Jan., 2010 13:20 IST
Post new comment