Chapter 6. Persistent ObjectsOnce you've described your persistence with Hibernate *.hbm.xml files and the corresponding Java sources, the basic mechanism for creating, updating, finding, and deleting objects is the Session class. This will be discussed in depth in the first part of the chapter. Hibernate makes an important distinction between transient objects and persistent objects. A transient object is not associated with a particular session. A persistent object is associated with a session. This can be a subtle (and confusing) distinction when working with Hibernate, but it's important to keep in mind that the objects you are working with may not represent the correct state of affairs as represented in the database outside the context of a session. The notion of persistent and transient objects is intertwined with the notion of object identity. The review of the session interface will be followed by an in-depth look at the various notions of identity. As long as you stick to a single thread per net.sf.hibernate.Session object, Hibernate will largely take care of identity automatically, but it can be confusing if you encounter problems related to identity (in particular, if you make use of composite identifiers). Finally, the life-cycle methods provided by Hibernate will be reviewed. These methods allow the receipt of events at various points in an object's existence. Sample code for a simple object is shown, and can be used as the base for your own laboratory experiments with object identity. |
Saturday, November 7, 2009
Chapter 6. Persistent Objects
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment