-->
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: Merge sets foreign key to null on a list mapping
PostPosted: Wed Apr 06, 2005 3:48 pm 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0 source
Mapping documents:
Code:
<hibernate-mapping package="com.llic.ides">
  <class name="Bloomberg" table="Bloomberg">
   
   <meta attribute="implement-equals">true</meta>
   <meta attribute="generated-class">com.llic.ides.base.BloombergBase</meta>
   
    <id name="id" column="bloombergid" type="java.lang.Long">
      <meta attribute="use-in-equals">true</meta>
     
      <generator class="native" />
     
    </id>

   .... properties ...
 

    <list name="options" lazy="false" cascade="all-delete-orphan">
       <key column="bloombergid"/>
       <list-index column="optionIndex"/>
       <one-to-many class="Option"/>
    </list>
   
     <list name="spEMiniFutures" lazy="false"  cascade="all-delete-orphan">
       <key column="bloombergid"/>
       <list-index column="futureIndex"/>
       <one-to-many class="SPEMiniFuture"/>
    </list>

   
  </class>
</hibernate-mapping>



Option mapping

Code:
<hibernate-mapping package="com.llic.ides">
  <class name="Option" table="Option">
   
   <meta attribute="implement-equals">true</meta>
   <meta attribute="generated-class">com.llic.ides.base.OptionBase</meta>
   
    <id name="id" column="optionid" type="java.lang.Long">
      <meta attribute="use-in-equals">true</meta>
     
      <generator class="native" />
     
    </id>
   
    ...generic properties ... 
   
   
    <many-to-one name="bloomberg" class="Bloomberg" column="bloombergid" cascade="all-delete-orphan"/>
   
   

   
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
public void testSaveOrUpdate() throws DataAccessException {
      bloomberg = (Bloomberg) dao.saveOrUpdate(bloomberg);

      Double divRate = new Double(20000);
      bloomberg.setDividendRateAtClose(divRate);
                 
                //calls session.merge(bloomberg)
      bloomberg = (Bloomberg) dao.saveOrUpdate(bloomberg);

      bloomberg = (Bloomberg) dao.findById(bloomberg.getId());

      assertTrue("updated", divRate
            .equals(bloomberg.getDividendRateAtClose()));
   }


Name and version of the database you are using:
MySQL 4.0


When I execute the merge call, all Option objects in the "options" list get updated. The bloombergid gets set to null. Can anyone explain why this is happening? I have check the objects in debug mode, and all of the entries in the "options" collection have an id that has been generated by the database.

Thanks,
Todd


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.