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
|
|