Interesting. Remember I mentioned ages ago I was getting an issue because I was using a single em for my main stuff in a session and then using another for my queries. But my stack trace was still relating to detached entities but non mentioned the SingleFeieldManager.
-----Original Message----- From: Daryl Stultz [mailto:[email protected]] Sent: Tuesday, 22 September 2009 2:33 AM To: [email protected] Subject: Re: SingleFieldManager crash On Fri, Sep 18, 2009 at 1:53 PM, C N Davies <[email protected]> wrote: > Sure I added some debug code, I'll run a unit test and come back to you > when > it fails with this specific SingleFieldManager exception. > > While following a hunch that my problem was related to multi-threading, I accidently managed to reproduce my original stack trace exactly, including the PK of the FailedObject! The problem isn't with multi-threading per se, but "multi em". It seems this error is thrown when the referenced object is currently managed by a *different* em. This should illustrate: EntityManagerFactory factory = getEntityManagerFactory(); EntityManager em1 = factory.createEntityManager(); B b = em1.find(B, 1); //em.close(); EntityManager em2 = factory.createEntityManager(); em2.getTransaction().begin(); A a = new A(); a.setB(b); em2.persist(a); em2.getTransaction().commit(); Uncomment em.close() and it works. So now to figure out if this is the source of my problem - it's possible some freak condition causes my initial em to stay open. -- Daryl Stultz _____________________________________ 6 Degrees Software and Consulting, Inc. http://www.6degrees.com mailto:[email protected]
