users@glassfish.java.net

Re: EJB 3.0 PE Write with Concurrent Users: Transaction Rollback Exception

From: <glassfish_at_javadesktop.org>
Date: Tue, 08 Apr 2008 13:18:01 PDT

> i use the same EM for all the concurrent users

That is the cause of the problem. Entity manager is not thread safe.

So for example you can't inject

@PersistenceContext(unitName = "myunit")
private EntityManager em;

into a servlet, even though it will allow you to do it, and will work until concurrent users start accessing the servlet (since there is only one instance of servlet class that executes all requests by default).

Read http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html
what is written there also applies for your case, since you use the same EM concurrently.
[Message sent by forum member 'jarol1' (jarol1)]

http://forums.java.net/jive/thread.jspa?messageID=268244