Hi!
I try to update one to many tables the parent is sa1,and the child is sa2
,the code is.
public int save(Sa1 bean, Implementation impl)
{
int cnt = 0;
Database db = impl.newDatabase();
try {
db.open("sy", Database.OPEN_READ_WRITE);
Transaction tx = impl.newTransaction();
tx.begin();
OQLQuery query = impl.newOQLQuery();
query.create("select sa1s from " + Sa1.class.getName() + " where
sa1_ord = $1");
query.bind(bean.getSa1_ord());
DList result = (DList) query.execute();
cnt = result.size();
if (cnt != 0) {
Sa1 toBeEdited = (Sa1) result.get(0);
tx.lock(toBeEdited, Transaction.WRITE);
try {
PropertyUtils.copyProperties(toBeEdited,bean);
} catch (Throwable t) {}
tx.commit();
}
else {
try {
tx.lock(bean, Transaction.WRITE);
tx.commit();
}catch (Throwable t) {}
}
}
catch (ODMGException ex) {}
return cnt;
}
When I do the function once to update the two table,the parent table update
successfully,
But the child table with the same key will be deleted.
When I do the function twice , the child table inserted the old value in the
bean.
If I do it again,all data are updated nice.
When I update the value in parent table,the same problem happened.
If I change the code to do the commit twice like
if (cnt != 0) {
Sa1 toBeEdited = (Sa1) result.get(0);
tx.lock(toBeEdited, Transaction.WRITE);
try {
PropertyUtils.copyProperties(toBeEdited,bean);
} catch (Throwable t) {}
tx.commit();
tx.begin();
tx.lock(toBeEdited, Transaction.WRITE);
tx.commit();
}
The data in child table will not be deleted(ok),But the data child table
will not be updated until the data in parent table changed.
the autoupdate in repository.xml both are 'fault',system will throw an error
if set to true.
What's the problem.
Best Regards
Johnson
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]