Hi,
the modeling of your intermediate EventSpeaker class is really strange.
Fist of all, you have a property speakerID and a association to speaker. What do you need the property for?
But the real problem is, that you have an eventId that is never set.
Why do you not modle your EventSpeaker like this:
Code:
<hibernate-mapping>
<class name="cEventSpeaker" table="EVENT_SPEAKER">
<id name="id" column="uid" type="long">
<property name="owner" type="string"/>
<many-to-one name="event"
column="EVENTID_ID"
class="Event"
not-null="true"
cascade="none"
/>
<many-to-one name="speaker"
column="SPEAKER_ID"
class="Speaker"
not-null="true"
cascade="none"
/>
</class>
</hibernate-mapping>
And when you create the association you do something like this:
Code:
Event event = (Event)session.load(Event.class, new Long(1));
Speaker speaker = (Speaker)session.load(Speaker.class, new Long(1));
EventSpeaker eventSpeaker = new EventSpeaker();
eventSpeaker.setEvent(event);
eventSpeaker.setSpeaker(speaker);
session.saveOrUpdate(eventSpeaker);
Bye the way, the problem in your code most likely comes from your call
event.getSpeakers().add(es); During this call Hibernate has to load the lazy association from event to EventSpeaker and has to write all the changes made before into the DB. And at that moment EventSpeaker has no event set...
Regards,
Joern