-->
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: one-to-one relationship not updating foreign key
PostPosted: Sat May 15, 2004 1:04 am 
Newbie

Joined: Thu May 06, 2004 1:20 pm
Posts: 7
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.


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.