}
public void testEmbeddedId() throws Exception {
ClassMetaData cmd = repo.getMetaData(EmbeddedIdEntity.class, null, true);
try {
JPAFacadeHelper.toOpenJPAObjectId(cmd, new EmbeddedIdEntity());
fail("Didn't fail!");
} catch (UserException re) {
// expected
}
// Initialize and persist entity
EmbeddedIdClass id = new EmbeddedIdClass();
id.setPk1(1);
id.setPk2(2);
EmbeddedIdEntity entity = new EmbeddedIdEntity();
entity.setId(id);
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();
em.clear();
// Find the entity and retrieve the objectId we use internally
EmbeddedIdEntity persistedEntity = em.find(EmbeddedIdEntity.class, id);
StateManagerImpl smi = ((StateManagerImpl) ((PersistenceCapable) persistedEntity).pcGetStateManager());
Object oid = smi.getObjectId();
assertEquals(oid, JPAFacadeHelper.toOpenJPAObjectId(cmd, id));
}