OpenJPA does not detect changes made via reflection; you need to call
OpenJPAEntityManager.dirty(o, "fieldName") to tell OpenJPA that they
changed. This is because the bookkeeping cost of attempting to scan all
instances that were loaded in a transaction can quickly become prohibitively
expensive.

Also, why are you doing the copy? EntityManager.merge() should take care of
copying old values onto the managed instance automatically.

-Patrick

On 7/14/07, Alessandro Ferrucci <[EMAIL PROTECTED]> wrote:

Yo guys,

I'm attempting to update an entity like so

manager.getTransaction().begin();
//attach entity to pers. context
//works fine
Obejct oldObj = doRead(newObj, manager);

//copy fields in newObj to oldObj
doMerge(oldObj,newObj);

//commit trans.
manager.getTransaction().commit();

here's the impl of doMerge, simple stuff...

private void mergeAdapter(IJPAAdapter src, Object dest)
    {
        Field[] destFields = dest.getClass().getDeclaredFields();

        try
        {
            for (Field f : destFields)
            {
                if (!(f.isAnnotationPresent(Transient.class)))
                {
                    f.setAccessible(true);
                    f.set(dest, f.get(src));
                }
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

The fields get copied fine, however this changed entity never gets updated
in the data store.


however, if I create a copy method within my entity class which copies the
fields from the other object....this works fine.

I cannot figure out why the reflective solution wouldn't work but the
second
would.  Any thoughts?

thx a bunch

--
alessandro ferucci =]




--
Patrick Linskey
202 669 5907

Reply via email to