em.persist(lStored);
em.getTransaction().commit();
lStored = em.find(Leaf.class, l.getId());
for (Alternative a : alternatives) {
Values values = lStored.getValues(a.getName());
assertEquals(4, ((PositiveIntegerValue) values.getValue(0)).getValue());
assertEquals(1, ((PositiveIntegerValue) values.getValue(1)).getValue());
}
lStored.initValues(alternatives, 5, true);
for (Alternative a : alternatives) {
for (int idx = 2; idx <= 4; idx++) {
Value v = lStored.getValues(a.getName()).getList().get(idx);
((PositiveIntegerValue) v).setValue(idx+1);
}
}
em.getTransaction().begin();
em.persist(lStored);
em.getTransaction().commit();
em.close();
// check order with new connection, this time don't recreate schema
em = newConnection();
assertNotNull(em);
em.getTransaction().begin();
lStored = em.find(Leaf.class, l.getId());
for (Alternative a : alternatives) {
Values values = lStored.getValues(a.getName());
assertEquals(4, ((PositiveIntegerValue) values.getValue(0)).getValue());
assertEquals(1, ((PositiveIntegerValue) values.getValue(1)).getValue());
assertEquals(3, ((PositiveIntegerValue) values.getValue(2)).getValue());
assertEquals(4, ((PositiveIntegerValue) values.getValue(3)).getValue());
assertEquals(5, ((PositiveIntegerValue) values.getValue(4)).getValue());
}
assertEquals("Removed values (orphans) should be automatically deleted", 15,
((Long)em.createQuery("select count(*) from Value").getSingleResult()).longValue());