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());
  }
  public void testQueryWithCustomIdPolicy() {
    setupCustomIdentifierPolicy("___", "PREFIX", "SUFFIX", "UpperCase");

    Flight f1 = new Flight();
    f1.setOrigin("BOS");
    f1.setDest("MIA");
    f1.setMe(2);
    f1.setYou(4);
    f1.setName("Harold");
    f1.setFlightNumber(400);
    pm.makePersistent(f1);

    Flight f2 = new Flight();
    f2.setOrigin("BOS");
    f2.setDest("MIA");
    f2.setMe(2);
    f2.setYou(4);
    f2.setName("Harold2");
    f2.setFlightNumber(401);
    pm.makePersistent(f2);

    Query q =
        pm.newQuery(
            "select from "
                + Flight.class.getName()
                + " where flightNumber > 300 "
                + " order by flightNumber desc");
    @SuppressWarnings("unchecked")
    List<Flight> result = (List<Flight>) q.execute();
    assertEquals(2, result.size());
    assertEquals(f2, result.get(0));
    assertEquals(f1, result.get(1));

    q =
        pm.newQuery(
            "select from "
                + Flight.class.getName()
                + " where name == \"Harold\" "
                + " order by name desc");
    @SuppressWarnings("unchecked")
    List<Flight> result2 = (List<Flight>) q.execute();
    assertEquals(1, result2.size());
    assertEquals(f1, result2.get(0));
  }
  public void testInsertWithCustomIdPolicy() throws EntityNotFoundException {
    setupCustomIdentifierPolicy("___", "PREFIX", "SUFFIX", "UpperCase");

    Flight f1 = new Flight();
    f1.setOrigin("BOS");
    f1.setDest("MIA");
    f1.setMe(2);
    f1.setYou(4);
    f1.setName("Harold");
    f1.setFlightNumber(400);
    pm.makePersistent(f1);
    Entity entity = ds.get(KeyFactory.stringToKey(f1.getId()));
    assertNotNull(entity);
    assertEquals(
        "PREFIX" + Flight.class.getSimpleName().toUpperCase() + "SUFFIX", entity.getKind());
    assertEquals("Harold", entity.getProperty("NAME"));
    // column name isn't generated if explicitly set
    assertEquals(400L, entity.getProperty("flight_number"));
  }