public void testSubclassOperationsOnOpenJPADefined() {
opsHelper(true, false);
}
private void opsHelper(boolean sub, boolean userDefined) {
OpenJPAEntityManager em = null;
try {
UnenhancedType un = newInstance(sub);
em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(un);
un.setStringField("bar");
assertEquals("bar", un.getStringField());
assertPersistenceContext(em, un, true, true, sub);
em.flush();
assertPersistenceContext(em, un, true, true, sub);
assertTrue(un.getId() != 0);
UnenhancedType un2 = em.find(getUnenhancedClass(), un.getId());
assertSame(un, un2);
em.getTransaction().commit();
assertPersistenceContext(em, un, false, false, sub);
un2 = em.find(getUnenhancedClass(), un.getId());
assertSame(un, un2);
if (!userDefined) {
em.close();
em = emf.createEntityManager();
}
un = em.find(getUnenhancedClass(), un.getId());
assertNotNull(un);
if (!userDefined)
assertTrue(un instanceof PersistenceCapable);
assertEquals("bar", un.getStringField());
em.getTransaction().begin();
un.setStringField("baz");
assertPersistenceContext(em, un, true, true, sub);
assertEquals("baz", un.getStringField());
if (sub)
((UnenhancedSubtype) un).setIntField(17);
assertTrue(em.isDirty(un));
em.getTransaction().commit();
// make sure that the values are still up-to-date after
// the commit happens
assertEquals("baz", un.getStringField());
em.close();
em = emf.createEntityManager();
un = em.find(getUnenhancedClass(), un.getId());
assertNotNull(un);
assertTrue(un instanceof PersistenceCapable);
assertEquals("baz", un.getStringField());
if (sub)
assertEquals(17, ((UnenhancedSubtype) un).getIntField());
em.close();
} finally {
if (em != null && em.getTransaction().isActive())
em.getTransaction().rollback();
if (em != null && em.isOpen())
em.close();
}
}