Also Rick in a separate issue while have my test rig can you also test the following. If in MasterClass you remove the psuedo pk getters and setters and make method like (which I would have originally thought the best way to model it):
@Id @OneToOne(cascade = { javax.persistence.CascadeType.ALL }, targetEntity = KeyClass.class) public KeyInterface getKey() { return key; } Then I get following exception: <openjpa-2.2.0-r422266:1244990 fatal store error> org.apache.openjpa.persistence.RollbackException: Attempt to assign id "0" to new instance "test.MasterClass-0" failed; there is already an object in the L1 cache with this id. You must delete this object (in a previous transaction or the current one) before reusing its id. This error can also occur when a horizontally or vertically mapped classes uses auto-increment application identity and does not use a hierarchy of application identity classes. FailedObject: test.MasterClass-0 Here is test case to trigger it @Test public void testTwoBeansInOneTransaction() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { List<Class<?>> classes = new ArrayList<Class<?>>(); classes.add(MasterClass.class); classes.add(DetailClass.class); classes.add(KeyClass.class); EntityManagerFactory emf = testClass(classes, false); EntityManager em = emf.createEntityManager(); Class<?> masterClassClass = Thread.currentThread().getContextClassLoader().loadClass(MasterClass.class.getName()); Class<?> keyClassClass = Thread.currentThread().getContextClassLoader().loadClass(KeyClass.class.getName()); EntityTransaction t = em.getTransaction(); IMasterClass mc1 = (IMasterClass) masterClassClass.newInstance(); KeyInterface key1 = (KeyInterface) keyClassClass.newInstance(); IMasterClass mc2 = (IMasterClass) masterClassClass.newInstance(); KeyInterface key2 = (KeyInterface) keyClassClass.newInstance(); t.begin(); key1.setUniqueField1("u1"); mc1.setKey(key1); em.persist(mc1); key2.setUniqueField1("u2"); mc2.setKey(key2); em.persist(mc2); t.commit(); em.close(); } -- View this message in context: http://openjpa.208410.n2.nabble.com/unexpected-error-there-is-already-an-object-in-the-L1-cache-with-this-id-tp7581176.html Sent from the OpenJPA Users mailing list archive at Nabble.com.