Chapter 4. Working with persistent objects

 

This chapter covers

  • The lifecycle of objects in an NHibernate application
  • Using the session persistence manager
  • Transitive persistence
  • Efficient fetching strategy

You now understand how NHibernate and ORM solve the static, structural aspects of the object/relational mismatch introduced in section 1.3.1. More specifically, you learned how object-oriented structures can be mapped to relational database structures to address issues of granularity, identity, inheritance, polymorphism, and associations.

This chapter covers another crucial subject—the dynamic, behavioral aspects of the object/relational mismatch. Success with NHibernate will not be guaranteed by simply mapping your domain classes to your databases. You must understand the dynamic nature of the problems that come into play at runtime, and which greatly affect the performance and stability of your applications. In our experience, many developers focus mostly on the structural mismatch and rarely pay attention to the more dynamic behavioral aspects.

In this chapter, we discuss the lifecycle of objects—how an object becomes persistent, and how it stops being considered persistent—and the method calls and other actions that trigger these transitions. The NHibernate persistence manager, the ISession, is responsible for managing object state, so you’ll learn how to use this important API.

4.1. The persistence lifecycle

4.2. The persistence manager

4.3. Using transitive persistence in NHibernate

4.4. Retrieving objects

4.5. Summary