I have what I think is a very simple many-to-many relationship, 2 tables "m_events" & "m_speakers" joined in table "event_speakers"
////////////////////////////////////////////////////////////////
<hibernate-mapping>
<class name="test.SpeakerManyToMany" table="m_speakers">
<id name="id" column="id" type="long">
<generator class="increment"/>
</id>
<property name="firstName" type="string" length="20"/>
<property name="lastName" type="string" length="20"/>
<set name="events" table="event_speakers" cascade="all">
<key column="speaker_id"/>
<many-to-many class="test.EventManyToMany"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="test.EventManyToMany" table="m_events">
<id name="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<property name="name" type="string" length="100"/>
<set name="speakers" table="event_speakers" cascade="all" inverse="true">
<key column="event_id"/>
<many-to-many class="test.SpeakerManyToMany"/>
</set>
</class>
</hibernate-mapping>
////////////////////////////////////////////////////////////////
Test code -
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
EventManyToMany event = new EventManyToMany();
event.setName("Inverse test");
event.getSpeakers().add(new SpeakerManyToMany("John", "Smith", event));
event.getSpeakers().add(new SpeakerManyToMany("Dave", "Smith", event));
event.getSpeakers().add(new SpeakerManyToMany("Joan", "Smith", event));
session.save(event);
tx.commit();
HibernateUtil.closeSession();
HibernateUtil.sessionFactory.close();
////////////////////////////////////////////////////////////////
All 3 tables are populated but the event_id column in "event_speakers" is null and speaker_id is set correctly.
If I move inverse="true" in to the first file then event_id column in "event_speakers" is now set correct but speaker_id is null
inverse="true" in both files does not insert a record into "event_speakers"!
How can I do this so both event_id & speaker_id are set correctly? - this is really doing my head in, I've tried every combinantion I can think of but it just doesn't for what I want!
Probably something stupid I'm doing/not doing but any ideas?
thanks
harry