}
public void testCompositeDerivedId() throws Exception {
ClassMetaData cmd = repo.getMetaData(Book.class, null, true);
try {
JPAFacadeHelper.toOpenJPAObjectId(cmd, new Book());
fail("Didn't fail!");
} catch (UserException re) {
// expected
}
String bookName = "Harry Potter";
String libName = "Library Name";
Library entity = new Library();
entity.setName(libName);
Book book = new Book();
book.setName(bookName);
entity.addBook(book);
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();
em.clear();
BookId id = new BookId();
id.setName(bookName);
id.setLibrary(libName);
Book persistedEntity = em.find(Book.class, id);
StateManagerImpl smi = ((StateManagerImpl) ((PersistenceCapable) persistedEntity).pcGetStateManager());
Object oid = smi.getObjectId();
assertEquals(oid, JPAFacadeHelper.toOpenJPAObjectId(cmd, id));
}