Chapter 21. A Parent/Child Example
21.1. About the Parent/Child Example
One of the first things that new users want to do with Hibernate is to model a parent/child type relationship. There are two different approaches to this. The most convenient approach, especially for new users, is to model both
Parent
and Child
as entity classes with a <one-to-many>
association from Parent
to Child
. The alternative approach is to declare the Child
as a <composite-element>
. The default semantics of a one-to-many association in Hibernate are much less close to the usual semantics of a parent/child relationship than those of a composite element mapping. We will explain how to use a bidirectional one-to-many association with cascades to model a parent/child relationship efficiently and elegantly.