datanucleus.allowAttachOfTransient
When you call PM.makePersistent with a transient object (with PK fields set), if you enable this feature then it will first check for existence of an object in the datastore with the same identity and, if present, will merge into that object (rather than just trying to persist a new object). {true, false} URL: http://www.datanucleus.org/products/datanucleus/jdo/persistence.html
However when executed results in unique constraint violation, as datanucleus tries to insert a record, instead of updating..
Code snippet..
Account account = new account();
account.setAccountNo(12345); //primary key - existing account in db
account.setOtherAttribute("other attrib");
persist (account);
......
persist(account)
{
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("Account");
PersistenceManager pm = pmf.getPersistenceManager();
pm.setProperty("datanucleus.allowAttachOfTransient", true);
Transaction tx=pm.currentTransaction();
try
{
tx.begin();
pm.makePersistent(account);
tx.commit();
}
}
Can someone help?
Thanks & Regards
Bharani