public void testInsert_NamedKey() {
Entity bookEntity = Book.newBookEntity("parent named key", "max", "123456", "manifesto");
ds.put(bookEntity);
Key bookKey = bookEntity.getKey();
Key key = new Entity(HasStringAncestorStringPkJPA.class.getSimpleName(), "named key", bookKey).getKey();
HasStringAncestorStringPkJPA ha = new HasStringAncestorStringPkJPA(null, KeyFactory.keyToString(key));
beginTxn();
em.persist(ha);
commitTxn();
Key keyWithParent = KeyFactory.stringToKey(ha.getId());
assertEquals(bookKey, keyWithParent.getParent());
// now we'll issue an ancestor query directly against the datastore and see
// if our object comes back.
Query q = new Query(ha.getClass().getSimpleName());
q.setAncestor(bookKey);
Entity result = ds.prepare(q).asSingleEntity();
assertEquals(bookKey, result.getKey().getParent());
assertEquals("named key", result.getKey().getName());
assertEquals("parent named key", result.getKey().getParent().getName());