public void testOneToManyUpgrade() {
// Persist using original storage version
switchDatasource(PersistenceManagerFactoryName.originalStorageVersion);
// Do the writes with the relationship managed via Key
SideB sideB1 = new SideB();
sideB1.setName("yar");
beginTxn();
pm.makePersistent(sideB1);
commitTxn();
SideB sideB2 = new SideB();
sideB2.setName("bar");
beginTxn();
pm.makePersistent(sideB2);
commitTxn();
HasOneToManyWithKey withKey = new HasOneToManyWithKey();
withKey.addOther(KeyFactory.createKey("UnownedUpgradeJDO$SideB", sideB1.getId()));
withKey.addOther(KeyFactory.createKey("UnownedUpgradeJDO$SideB", sideB2.getId()));
beginTxn();
pm.makePersistent(withKey);
commitTxn();
beginTxn();
assertEquals(2, pm.getObjectById(
HasOneToManyWithKey.class, withKey.getId()).getOthers().size());
commitTxn();
// Read back in using latest storage version, as unowned
Map<String, String> props = Utils.newHashMap();
props.put("datanucleus.appengine.datastoreEnableXGTransactions", Boolean.TRUE.toString());
switchDatasource(PersistenceManagerFactoryName.transactional, props);
beginTxn();
HasOneToManyWithUnowned withUnowned =
pm.getObjectById(HasOneToManyWithUnowned.class, withKey.getId());
assertEquals(2, withUnowned.getOthers().size());
assertEquals(sideB1.getId(), withUnowned.getOthers().get(0).getId());
assertEquals(sideB2.getId(), withUnowned.getOthers().get(1).getId());
commitTxn();
}