Running this example code:
public static void main(String[] args) { PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("test.odb"); PersistenceManager pm = pmf.getPersistenceManager(); pm.currentTransaction().begin(); TestClass test = new TestClass(1234,"test"); pm.makePersistent(test); System.out.println(JDOHelper.isPersistent(test)); pm.currentTransaction().commit(); List<TestClass> list = (List<TestClass>) pm.newQuery(TestClass.class).execute(); TestClass first = list.get(0); TestClass detached = pm.detachCopy(first); System.out.println(JDOHelper.isDetached(detached)); pmf.close(); }
With this as the persistent class:
@PersistenceCapable(detachable="true") public class TestClass implements Serializable { @PrimaryKey private long id; private String name; protected TestClass() { } public TestClass(long id,String name) { this.id = id; this.name = name; } /** * @return the name */ public String getName() { return name; } /** * @return the id */ public long getId() { return id; } }
Prints out the following:
true false
So it seems that the JDOHelper.isDetached method isn't doing what it should?