// Add a Sub to the Main
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
HasVersionMain main = em.find(HasVersionMain.class, mainKey);
HasVersionSub s = new HasVersionSub();
s.setKey(mainKey, "Init db #0");
main.getSubs().add(s);
em.getTransaction().commit();
em.close();
// Get and detach Main (1)
em = emf.createEntityManager();
em.getTransaction().begin();
HasVersionMain m1 = em.find(HasVersionMain.class, mainKey);
m1.getSubs(); // Make sure subs are loaded
HasVersionSub s1 = m1.getSubs().get(0);
s1.getValue(); s1.getVersion();
assertNotNull("Version on element is null", JDOHelper.getVersion(s1));
em.getTransaction().commit();
em.close();
// Get and detach Main (2)
em = emf.createEntityManager();
em.getTransaction().begin();
HasVersionMain m2 = em.find(HasVersionMain.class, mainKey);
m2.getSubs(); // Make sure subs are loaded
HasVersionSub s2 = m2.getSubs().get(0);
s2.getValue(); s2.getVersion();
assertNotNull("Version on element is null", JDOHelper.getVersion(s2));
em.getTransaction().commit();
em.close();
// Update both detached objects
s1.incValue(2);
s2.incValue(3);
// Merge m1
em = emf.createEntityManager();
em.getTransaction().begin();
em.merge(m1);