This article, the third in our series on Hibernate, focuses on the life-cycle states of persistent objects and associations. These concepts are put to work with continued development of an application that was created in the first two articles of this series.
Hibernate: Understanding Associations (Page 1 of 4 )
Relationships between entities form the crux of the relational approach. This must be well reflected by an ORM framework. In the world of the object-oriented approach, relations between objects are represented by associations. So the task of any ORM framework is to create a mapping between the relationships and the associations. This mapping is known as an association. The term is the same as that of the object oriented approach.
But before going into the depths of associations and how they affect queries, one must understand the life-cycle of the persistent object. This is necessary because queries depend on the current state of the object. Most of the logical errors occur due to operations tried on the persistent objects without keeping their current state in mind. In short, most of the "gotchas" in Hibernate can be corollated with the developer overlooking the state.
Hence this discussion will focus on both the life-cycle states of persistent objects and associations. The first section will deal with the life-cycle of the persistent object. In the second section I will discuss associations. The third section will put the concepts to work, as I will extend the application which was being developed during previous parts to include one more table with a many to one relationship with the order table. Now that the agenda has been disclosed, l will get right into the topic.