5 Ocak 2016 Salı

Hibernate object states

States of objects that are mapped to Hibernate:

1.     Transient objects:
a.     These objects are in heap memory,
b.     Hibernate doesn't manage these objects,
c.      To persist any changes to these objects, we have to ask the session to save the transient object to the DB! At this point Hibernate assigns the object an identifier and marks the object as being in a persistent state.
2.     Persistent objects:
a.     Exist in the DB,
b.     Hibernate manages the persistence for these types of objects,
c.      If there is any change on these objects, Hibernate will keep the DB up to date.
3.     Detached objects:
a.     Have a representation in the DB but changes will not be reflected to the DB,
b.     Or vice versa of a,
c.      To create a detached object:
                                               i.     Close the session of an object that it was associated with,
                                              ii.     Evicting the object from the session by calling evict method.
d.     In order to persist any changes of a detached object, it must be attached to a Hibernate session.
4.     Removed objects:
a.     Managed by Hibernate sessions,
b.     Deleted at the end of the session (because they are marked as to be deleted)

Hiç yorum yok:

Yorum Gönder