Este contenido no está disponible en el idioma seleccionado.
1.2. Part 2 - Mapping associations
So far we have mapped a single persistent entity class to a table in isolation. Let us 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.
1.2.1. Mapping the Person class Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
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.