use of org.eclipse.persistence.testing.models.jpa.xml.advanced.dynamic.MyDynamicEntity in project eclipselink by eclipse-ee4j.
the class EntityMappingsDynamicAdvancedJUnitTestCase method testDynamicWithNoPersistenceXML.
/**
* Test a dynamic persistence unit using no persistence.xml.
*/
public void testDynamicWithNoPersistenceXML() {
// This is a Java SE feature only.
if (!isOnServer()) {
List<ClassDescriptor> descriptors = new ArrayList<ClassDescriptor>();
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClassName("org.eclipse.persistence.testing.models.jpa.xml.advanced.dynamic.MyDynamicEntity");
descriptor.setAlias("MyDynamicEntity");
descriptor.setTableName("JPA_DYNAMIC_ENTITY");
descriptor.addPrimaryKeyFieldName("ID");
descriptor.setSequenceNumberFieldName("ID");
descriptor.setSequenceNumberName("DYNAMIC_SEQ");
descriptor.addDirectMapping("id", "ID");
descriptor.addDirectMapping("firstName", "F_NAME");
descriptor.addDirectMapping("lastName", "L_NAME");
descriptors.add(descriptor);
EntityManager em = createDynamicEntityManager("dynamic-test", descriptors);
new DynamicTableCreator().replaceTables(((JpaEntityManager) em).getServerSession());
try {
beginTransaction(em);
em.persist(new MyDynamicEntity("Doug", "Clarke"));
em.persist(new MyDynamicEntity("Peter", "Krogh"));
commitTransaction(em);
clearCache("dynamic-test");
em.clear();
List<MyDynamicEntity> results = em.createQuery("SELECT d FROM MyDynamicEntity d").getResultList();
assertFalse("No dynamic entities were returned from the query", results.isEmpty());
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw e;
} finally {
closeEntityManager(em);
}
}
}
Aggregations