public void testSerializeWithOneToMany_AddChildToReattached() throws Exception { pm.setDetachAllOnCommit(true); beginTxn(); HasOneToManyListJDO pojo = new HasOneToManyListJDO(); pojo.setVal("yar"); BidirectionalChildListJDO bidir = new BidirectionalChildListJDO(); bidir.setChildVal("yar2"); pojo.addBidirChild(bidir); pm.makePersistent(pojo); commitTxn(); pm.close(); pm = pmf.getPersistenceManager(); pojo = toBytesAndBack(pojo); assertEquals("yar", pojo.getVal()); assertEquals(1, pojo.getBidirChildren().size()); beginTxn(); pojo = pm.makePersistent(pojo); BidirectionalChildListJDO bidir2 = new BidirectionalChildListJDO(); bidir.setChildVal("yar3"); pojo.addBidirChild(bidir2); bidir2.setParent(pojo); commitTxn(); Entity e = ds.get(KeyFactory.stringToKey(bidir2.getId())); assertEquals(KeyFactory.stringToKey(pojo.getId()), e.getKey().getParent()); }
public void testSerializeWithOneToMany_AddUnidirectionalChildToDetached() throws Exception { pm.setDetachAllOnCommit(true); beginTxn(); HasOneToManyListJDO pojo = new HasOneToManyListJDO(); pojo.setVal("yar"); Flight flight = new Flight(); flight.setName("harry"); pojo.addFlight(flight); pm.makePersistent(pojo); commitTxn(); pm.close(); pm = pmf.getPersistenceManager(); pojo = toBytesAndBack(pojo); assertEquals("yar", pojo.getVal()); assertEquals(1, pojo.getFlights().size()); Flight flight2 = new Flight(); flight2.setName("not harry"); pojo.addFlight(flight2); beginTxn(); pojo = pm.makePersistent(pojo); commitTxn(); Entity e = ds.get(KeyFactory.stringToKey(flight2.getId())); assertEquals(KeyFactory.stringToKey(pojo.getId()), e.getKey().getParent()); }