* Validates that an mapped superclass using field access and an
* entity subclass using property access get mapped properly.
* The subclass uses a storage field in the superclass.
*/
public void testMappedSuperField() {
OpenJPAEntityManagerSPI em = emf.createEntityManager();
PropertySub2 ps = new PropertySub2();
// Call super setter with underlying field access
ps.setName("MappedSuperName");
// 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("PropertySub2.query");
qry.setParameter("id", ps.getId());
qry.setParameter("name", "MappedSuperName");
qry.setParameter("crtDate", now);
PropertySub2 ps2 =
(PropertySub2)qry.getSingleResult();
assertEquals(ps, ps2);
assertEquals(ps2.getName(), "MappedSuperName");
assertEquals(ps2.getCreateDate().toString(), now.toString());
try {
qry = em.createNamedQuery("PropertySub2.badQuery");
qry.setParameter("id", ps.getId());
qry.setParameter("name", "MappedSuperName");
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 \"PropertySub2\"",
"[createDate, id, name]");
}
em.close();
}