I have read the forum extensively, but still can't figure out what I am doing wrong.
There is a one-to-one relationship between 'event' and 'repeatEvent'.
event.hbm.xml
Code:
<class name="Event" table="Events">
<id name="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="start" not-null="true"/>
<one-to-one name="repeatInfo" class="RepeatEvent" property-ref="eventId" cascade="all"/>
</class>
repeatEvent.hbm.xml
Code:
<class name="RepeatEvent" table="RepeatEvents" discriminator-value="0">
<id name="id">
<generator class="native"/>
</id>
<discriminator type="integer" column="repeatType"/>
<many-to-one not-null="true" name="eventId" class="Event" unique="true"/>
<property name="count"/>
<subclass name="RepeatEventDaily" discriminator-value="1">
<property name="onlyWeekdays"/>
</subclass>
</class>
main code
Code:
Event e = new Event();
e.setStart( new Date() );
RepeatEvent ed = new RepeatEventDaily();
ed.setCount(365);
e.setRepeatInfo(ed);
s.saveOrUpdate( e );
The error I get is:
Code:
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: eventId
If I remove the "not-null" from many-to-one, both tables are saved, but the "eventId" column in the repeatEvent table is null.
Your help is much appreciated.