Hi there!
I'm pretty new in hibernate. Currently trying to follow some exapmles from the book "Hibernate Quickly". there is a section about bidirectional manyTomany mapping. I gave it a try:
there are two classes that suposse to have this kind of mapping, Event and Attendee;
Attendee mapping: <set name="events" table="event_attendees" cascade="save-update"> <key column="attendee_id"/> <many-to-many class="Event"/> </set>
Event mapping: <set name="attendees" inverse="true"> <key column="event_id"/> <many-to-many column="attendee_id" class="Attendee"/> </set>
if I run org.hibernate.tool.hbm2ddl.SchemaExportTask on my project, there are two join tables created in DB: 1. event_attendees(attendee_id:bigint, elt:bigint) 2. events_attendees(event_id:bigint, attendee_id:bigint)
I don't quite understand why there are two tables, not just one that is defined in Attendee mapping. Also I don't what is the "elt" attribute in the first table. If I try to persist Attendee with a set of Events set on it, only one Event is inserted to DB. event_attendees get one entry as well. If I try to persist Event with set of Attendees, only the Event instance get persisted. No entries in both join tables. This is probably because "changes made to the inverse end of the associa- tion will not be persisted" - as the author says. I don't understand why only one side can persist its assotioans, while the other can't.
Thanx in advance for some hints, explanation.
|