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