Hi everyone,

I have some problem updating a persistent object with OTM Api, i'm trying to do it like in the otm tutorial : http://db.apache.org/ojb/otm-tutorial.html#More%20Sophisticated%20Transaction%20Handling

Here is my code :

public Object getObjectByIdentityQuery(Object object, int lockType) {
OTMKit kit = SimpleKit.getInstance();
OTMConnection conn = null;
Transaction tx = null;
try {
conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
tx = kit.getTransaction(conn);
boolean auto = !tx.isInProgress();
System.out.println(auto); if (auto) tx.begin();
Object result = conn.getObjectByIdentity(conn.getIdentity(object), lockType);
if (auto) tx.commit();
return result;
}
catch(Exception e) {
System.out.println("An error has occured on Properties.getObjectByIdentityQuery() \n");
e.printStackTrace() ; }
finally {
conn.close();
}
return null ;
}
public void updatePropertyByName(String propName, String propValue) {
OTMKit kit = SimpleKit.getInstance();
OTMConnection conn = null;
Transaction tx = null;
try {
conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
tx = kit.getTransaction(conn);
tx.begin();
SysProperties sample = new SysProperties();
sample.setPropertyName(propName); SysProperties propertyToUpdate = (SysProperties)getObjectByIdentityQuery(sample, LockType.WRITE_LOCK);
propertyToUpdate.setPropertyValue(propValue);
tx.commit();
}
finally {
conn.close();
}
}


My problem is the Transaction tx is not in progress when getObjectByIdentityQuery() is called from updatePropertyByName(), so tx.begin() is called and the changes aren't saved to the database.
I have tried doing it with an Iterator, exactly like the example but the same problem occurs.


Thanks
Jean-Francois Beaulac
trainee programmer @ www.beetext.com






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to