em.getTransaction().begin();
// create and persist the entities
List<IOrderedEntity> newEntities = new ArrayList<IOrderedEntity>();
for (int i=0; i<3; i++) {
IOrderedEntity newEntity = (IOrderedEntity)constructNewEntityObject(entityType);
newEntity.setId(i);
em.persist(newEntity);
newEntities.add(newEntity);
}
// create and persist the elements
Constructor<IColumnEntity> elementConstrctor = elementClass.getConstructor(String.class);
List<INameEntity> newElements = new ArrayList<INameEntity>();
IColumnEntity newElement;
for (int i=0; i<Element_Names.length; i++) {
newElement = elementConstrctor.newInstance(Element_Names[i]);
// add parent relationships
newElement.setEntities(newEntities);
em.persist(newElement);
newElements.add(newElement);
}
// update entities with elements
for (IOrderedEntity newEntity : newEntities) {
newEntity.setEntities(newElements);
em.persist(newEntity);
}
em.getTransaction().commit();
em.clear();
// verify the entities were stored
for (int i=0; i<Element_Names.length; i++) {
IOrderedEntity findEntity = em.find(entityClass, i);
assertNotNull("Found entity just created", findEntity);
assertEquals("Verify entity id = " + i, i, findEntity.getId());
assertEquals("Verify entity name = " + entityClass.getName(), entityClass.getName(),
findEntity.getClass().getName());
}
} catch (Throwable t) {
log.error(t);
throw new RuntimeException(t);
} finally {