These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: bidirectional ManyToMany mapping - unexpected behavior
PostPosted: Wed Jan 12, 2011 8:26 am 
Newbie

Joined: Thu Jan 06, 2011 11:48 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.