posted 16 years ago
Actually that error occurs when you try to "attach" an object that has the same id as an object that is already being managed.
For instance I can do this
MyObject someObjectICreateThatIsNotManaged = new MyObject();
someObjectICreateThatIsNotManaged.setId(1); //Yes setId should not be changable by code, but this is just for demonstration purposed
(Now within a Transaction/Session)
MyObject objectWithID1 = em.find(1,MyObject.class));
em.persist(someObjectICreateThatIsNotManaged); // This will get that exception thrown because objectWithID1 was loaded and is managed by the EntityManager, and when you then tried to "persist" someObjectICreateThatIsNotManaged, that object has the same id of 1 in it, and
someObjectICreateThatIsNotManaged != objectWithID1
Hope that helps clarify it.
Mark