EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
int nPart = 3;
tx.begin();
Shirt shirt = new Shirt();
String name = "Shirt: " + System.currentTimeMillis();
shirt.setTxeName(name);
String size = "L";
shirt.setSzeId(size);
int pid = (int) System.currentTimeMillis();
for (int i = 0; i < nPart; i++) {
Part part = new Part();
part.setPartName("Part");
part.getId().setPartNumber(pid++);
part.setShirt(shirt);
shirt.getParts().add(part);
}
em.persist(shirt);
tx.commit();
em.close();
int sid = shirt.getTextileId();
em = emf.createEntityManager();
shirt = em.find(Shirt.class, sid);
assertNotNull(shirt);
assertNotNull(shirt.getParts());
assertEquals(nPart, shirt.getParts().size());
}