Java Reference
In-Depth Information
CHAPTER 4
n n n
The Persistence Life Cycle
I n this chapter, we discuss the life cycle of persistent objects in Hibernate. These persistent
objects are POJOs without any special marker interfaces or inheritance related to Hibernate.
Part of Hibernate's popularity comes from its ability to work with a normal object model.
We also discuss the methods of the Session interface that are used for creating, retrieving,
updating, and deleting persistent objects from Hibernate.
Introduction to the Life Cycle
After adding Hibernate to your application, you do not need to change your existing Java
object model to add persistence marker interfaces or any other type of hint for Hibernate.
Instead, Hibernate works with normal Java objects that your application creates with the new
operator, or that other objects create. For Hibernate's purposes, these can be drawn up into
two categories: objects for which Hibernate has entity mappings, and objects that are not
directly recognized by Hibernate. A correctly mapped entity object will consist of fields and
properties that are mapped, and that are themselves either references to correctly mapped
entities, references to collections of such entities, or “value” types (primitives, primitive wrap-
pers, strings, or arrays of these).
Given an instance of an object that is mapped to Hibernate, it can be in any one of three
different states: transient, persistent, or detached.
Transient objects exist in memory, as illustrated in Figure 4-1. Hibernate does not manage
transient objects or persist changes to transient objects.
Figure 4-1. Transient objects are independent of Hibernate.
To persist the changes to a transient object, you would have to ask the session to save the
transient object to the database, at which point Hibernate assigns the object an identifier.
63
Search WWH ::




Custom Search