tags:

views:

180

answers:

1

My understanding of detach copy is that it makes a copy of your object so that you can make changes to it without the PersistenceManager noticing.

Since I close my PersistenceManager before passing the model object to the view to be used, I wouldn't have to call anything like detachCopy or makeTransient before passing it along would I?

The examples I looked at do call it though... This is the example I looked at from http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html:

public Employee getEmployee(User user) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Employee employee, detached = null;
    try {
        employee = pm.getObjectById(Employee.class,
            "[email protected]");

        // If you're using transactions, you can call
        // pm.setDetachAllOnCommit(true) before committing to automatically
        // detach all objects without calls to detachCopy or detachCopyAll.
        detached = pm.detachCopy(employee);
    } finally {
        pm.close();
    }
    return detached;
}
A: 

You can have objects detached automatically using the PMF prop, or detach copies of them manually, as the example says. Now what was the question?

DataNucleus
So it will throw an exception if I don't either detachCopy or makeTransient on it before closing the PM?
Kyle
what will throw an exception ? If you dont makeTransient, or detachCopy or have that PMF prop set then the objects migrate to HOLLOW state, as per the JDO spec.
DataNucleus
As per http://www.datanucleus.org/products/accessplatform/jdo/object_lifecycle.html
DataNucleus