update/merge of transient object using allowAttachOfTransient in datanucleus(JDO) not working


bharani.s@...
 

Datanucleus document says...


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


Andy
 

That is JPA API handling, to mimic what some other JPA providers think is a "detached" object, even though it is not. It is of no consequence in JDO.
You could easily enough contribute an update to docs if you have found something incorrect. Thx