use of org.eclipse.persistence.testing.models.jpa.extensibility.PhoneNumber in project eclipselink by eclipse-ee4j.
the class ExtensibilityTests method testMergeRefreshedManyToMany.
public void testMergeRefreshedManyToMany() {
EntityManagerFactory emf = getEntityManagerFactory();
persistEmployeeData(emf);
EntityManager em = emf.createEntityManager();
Employee emp = null;
PhoneNumber pn = null;
try {
beginTransaction(em);
emp = (Employee) em.createQuery("select e from ExtensibilityEmployee e where e.firstName = 'Joe'").getSingleResult();
pn = new PhoneNumber();
pn.setAreaCode("613");
pn.setNumber("1111111");
em.persist(pn);
List numbers = new ArrayList();
numbers.add(pn);
emp.putExt("phoneNumbers", numbers);
commitTransaction(em);
Map properties = new HashMap();
properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_FILE, "extension2.xml");
JpaHelper.getEntityManagerFactory(em).refreshMetadata(properties);
em.close();
em = emf.createEntityManager();
emp = em.merge(emp);
assertNull(emp.getExt("phoneNumbers"));
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
em.close();
deleteEmployeeData(emf);
}
}
use of org.eclipse.persistence.testing.models.jpa.extensibility.PhoneNumber in project eclipselink by eclipse-ee4j.
the class ExtensibilityTests method testOneToManyMapping.
public void testOneToManyMapping() {
EntityManagerFactory emf = getEntityManagerFactory();
persistEmployeeData(emf);
EntityManager em = emf.createEntityManager();
PhoneNumber pn = new PhoneNumber();
Employee emp = null;
try {
beginTransaction(em);
emp = (Employee) em.createQuery("select e from ExtensibilityEmployee e where e.firstName = 'Joe'").getSingleResult();
pn.setAreaCode("613");
pn.setNumber("1111111");
em.persist(pn);
List numbers = new ArrayList();
numbers.add(pn);
emp.putExt("phoneNumbers", numbers);
commitTransaction(em);
em.refresh(emp);
numbers = emp.getExt("phoneNumbers");
assertTrue("The phoneNumbers were not properly saved", numbers.size() == 1);
em.clear();
clearCache();
emp = (Employee) em.createQuery("select e from ExtensibilityEmployee e join e.phoneNumbers p where p.areaCode = '613'").getSingleResult();
assertTrue("queries on extended OneToMany mappings fail", emp != null);
assertTrue("queries on extended OneToMany mappings return incorrect results.", ((List) emp.getExt("phoneNumbers")).size() == 1);
} finally {
try {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
em.close();
deleteEmployeeData(emf);
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
}
}
}
Aggregations