이 콘텐츠는 선택한 언어로 제공되지 않습니다.
2.2. Part 2 - Mapping associations
So far we have mapped a single persistent entity class to a table in isolation. Let's expand on that a bit and add some class associations. We will add people to the application and store a list of events in which they participate.
2.2.1. Mapping the Person class
The first cut of the
Person
class looks like this:
Save this to a file named
src/main/java/org/hibernate/tutorial/domain/Person.java
Next, create the new mapping file as
src/main/resources/org/hibernate/tutorial/domain/Person.hbm.xml
Finally, add the new mapping to Hibernate's configuration immediately after the existing mapping for
Event.hbm.xml
:
<mapping resource="events/Event.hbm.xml"/> <mapping resource="events/Person.hbm.xml"/>
<mapping resource="events/Event.hbm.xml"/>
<mapping resource="events/Person.hbm.xml"/>
Create an association between these two entities. Persons can participate in events, and events have participants. The design questions you have to deal with are: directionality, multiplicity, and collection behavior.