// constructor calls KeyFactory.keyToString() to encode
// the Key values. See BookEncodedStringId.java.)
Key book4keyParent = new Builder("Publisher", "O'Reilly").getKey();
Key book4key = new Builder("BookEncodedStringId", "978-0-596-52272-8")
.getKey();
BookEncodedStringId book4 = new BookEncodedStringId(book4key,
book4keyParent);
em.persist(book4);
} finally {
em.close();