-->
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: saving new children updates siblings tiemstamp
PostPosted: Tue Oct 12, 2004 10:06 am 
Newbie

Joined: Tue Oct 12, 2004 9:31 am
Posts: 3
Hibernate 1.2.3
on MYSQL 4.0.1.7

When I try to save 2 new children of a parent child relationship, I find that all the timestamp fields of the siblings get updated also. I would like the timestamps of the existing children to remain as they are.

The parentobject is mapped as follows:

<class name="za.co.lawactive.dse.dao.impl.DstImpl"
table="dstDistribution">
<id name="pk" column="pk" type="java.lang.Long" unsaved-value="null">
<generator class="native" />
</id>

<bag role="dstTransaction" cascade="all" lazy="true">
<key column="fk"/>
<one-to-many class="za.co.lawactive.dse.dao.impl.DstTransImpl"/>
</bag>
</class>

The child object is mapped as follows:

<class name="za.co.lawactive.dse.dao.impl.DstTransImpl"
table="dstTransaction">
<id name="pk" column="pk" type="java.lang.Long" unsaved-value="null">
<generator class="native" />
</id>
<many-to-one name="dstDistribution" class="za.co.lawactive.dse.dao.impl.DstImpl" column="fk" />
</class>

I have tried vaiations of saving the new children:
1)
//iterate over the new children and set the parent object (tempDst)
//and save each new child
Iterator dstTransIt=dst.getDstTransaction().iterator();
while(dstTransIt.hasNext()){
DstTrans tempTrans=(DstTrans)dstTransIt.next();
tempTrans.setDstDistribution(tempDst);
session.save(tempTrans);
}
2)
//add each new child to the parent object and then flush the parent object
Iterator dstTransIt=dst.getDstTransaction().iterator();
while(dstTransIt.hasNext()){
DstTrans tempTrans=(DstTrans)dstTransIt.next();
tempDst.getDstTransaction().add(tempTrans);
}

In both instances the new children are correctly saved with new timestamps which are unfortunately applied to the older children as well


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.