(OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
createEntityManagerFactory("Access-XML",
"org/apache/openjpa/persistence/access/" +
"access-persistence.xml");
OpenJPAEntityManagerSPI em = emf1.createEntityManager();
XMLPropertySub ps = new XMLPropertySub();
// Call super setter with underlying field access
ps.setName("AbsMappedSuperName");
// Call base setter with property access
Date now = new Date();
ps.setCreateDate(now);
em.getTransaction().begin();
em.persist(ps);
em.getTransaction().commit();
em.clear();
// This value of a persistent field was set using the setter
// above, but this query will use the property name to verify that
// propety access is in use.
Query qry = em.createNamedQuery("XMLPropertySub.query");
qry.setParameter("id", ps.getId());
qry.setParameter("name", "AbsMappedSuperName");
qry.setParameter("crtDate", now);
XMLPropertySub ps2 =
(XMLPropertySub)qry.getSingleResult();
assertEquals(ps, ps2);
assertEquals(ps2.getName(), "AbsMappedSuperName");
assertEquals(ps2.getCreateDate().toString(), now.toString());
try {
qry = em.createNamedQuery("XMLPropertySub.badQuery");
qry.setParameter("id", ps.getId());
qry.setParameter("name", "AbsMappedSuperName");
qry.setParameter("crtDate", now);
qry.getSingleResult();
fail("Usage of this query should have thrown an exception");
}
catch (Exception e) {
assertExceptionMessage(e, ArgumentException.class,
"No field named \"crtDate\" in \"XMLPropertySub\"",
"[createDate, id, name]");
} finally {
em.close();
clear(emf1);
closeEMF(emf1);
}
}