Jay D. McHugh wrote:

>  Geronimo should not allow you to add container managed entity
>  managers to servlets. They would not be thread safe.

Then please examine the example again. You're correct that there's a
stateless bean acting as a accessor in _part_ of the example. But
there is also a servlet class called Test - search for Test.java in
that page.

http://cwiki.apache.org/GMOxDOC21/container-managed-persistence-with-jpa.html

You'll see that the servlet Test has a injected EntityManager. Now, I
didn't notice before but the servlet actually only accesses the entity
manager in a UserTransaction which it looks up per request. I'm not
sure if and how the transaction would make access to the single
instance entity manager thread safe though?

The blog linked below seems to suggest that even when using user
transactions - which on the other side seems very servlet injection
friendly - it is still wrong to share a entity manager instance in
servlets.

http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html

-- 
Fredrik Jonson

Reply via email to