pm.detachCopyは機能していますか?
Spring + ObjectDB(JDO)プログラムを作成しています。
PersistenceManager#detachCopyは、@ PersistenceCapable:detachableがtrueであるにもかかわらず、一時オブジェクトを返します。
これがサンプルコードです。
簡単なテストモデル(POJO)があります
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class TestModel {
@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
@PrimaryKey
private Long id;
@Persistent
private String name;
// getter, setter
}
取り外し可能は「true」に設定されます。
そしてダオは
public class TestModelDaoImpl {
private PersistenceManagerFactory persistenceManagerFactory;
public void setPersistenceManagerFactory(PersistenceManagerFactory pmf) {
this.persistenceManagerFactory = pmf;
}
public TestModel makePersistent(TestModel obj){
PersistenceManager pm = persistenceManagerFactory.getPersistenceManager();
Transaction tx = pm.currentTransaction();
tx.begin();
pm.makePersistent(obj);
System.out.println(" obj => " + JDOHelper.getObjectState(obj)); // => (1) persistent-new
TestModel detachedObj = pm.detachCopy(obj);
System.out.println(" detachedObj => " + JDOHelper.getObjectState(detachedObj)); // => (2) transient ..
tx.commit();
return detachedObj;
// try catch is omitted
}
}
(2)で切り離された状態になっていると思います。しかし、一時的です。
ObjectDBのバージョンは2.4.0_05です
application-context.xml
<bean id = "pmf" class = "org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
<property name = "jdoProperties">
<小道具>
<prop key = "javax.jdo.PersistenceManagerFactoryClass"> com.objectdb.jdo.PMF </ prop>
<prop key = "javax.jdo.option.ConnectionURL"> $ objectdb / db / testdb.odb </ prop>
<prop key = "javax.jdo.option.ConnectionUserName"> admin </ prop>
<prop key = "javax.jdo.option.ConnectionPassword"> admin </ prop>
</小道具>
</プロパティ>
</ bean>
<bean id = "jdoTransactionManager" class = "org.springframework.orm.jdo.JdoTransactionManager">
<property name = "persistenceManagerFactory">
<ref local = "pmfProxy" />
</プロパティ>
</ bean>
<bean id = "pmfProxy" class = "org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy">
<property name = "targetPersistenceManagerFactory" ref = "pmf" />
<property name = "allowCreate" value = "true" />
</ bean>