public void testTwiceMakePersistent() {
try {
String name = "testTwiceMakePersistent";
String strid;
PersistenceManager pm = pmf.getPersistenceManager();
StringUserId sui = new StringUserId(name, 123456);
pm.currentTransaction().begin();
pm.makePersistent(sui);
pm.currentTransaction().commit();
StringUserId sui2 = new StringUserId(name, 654321);
pm.currentTransaction().begin();
try {
pm.makePersistent(sui2);
fail("Same identifier not detected");
} catch (JDOException e) {
assertTrue("Object becomes persistent", !JDOHelper.isPersistent(sui2));
assertEquals("Bad f1 value in non peristent object", 654321, sui2.getF1());
}
pm.currentTransaction().commit();
sui = null;
pm.evictAll();
pm.currentTransaction().begin();
try {
pm.makePersistent(sui2);
pm.currentTransaction().commit();
fail("Same identifier not detected with empty cache");
} catch (JDOException e) {
if (pm.currentTransaction().isActive()) {
pm.currentTransaction().rollback();
}
assertTrue("Object becomes persistent", !JDOHelper.isPersistent(sui2));
assertEquals("Bad f1 value in non peristent object with empty cache",
654321, sui2.getF1());
}
pm.currentTransaction().begin();
sui = (StringUserId) pm.getObjectById(
pm.newObjectIdInstance(StringUserId.class, name), false);