geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tornike <torni...@gmail.com>
Subject Re: EntityManager & Servlets
Date Mon, 31 Aug 2009 16:42:32 GMT

Yes, but if it's in their example maybe it's OK for Geronimo to use container
managed EntityManager with the servlet and there won't be any threading
issues. If it's true then we wouldn't need any EJB's in the project and
simply communicate to JPA entities even when using container managed
EntityManager. As far as I know this method is discouraged but if it's ok to
do in Geronimo it would greatly simplify many projects. 



Fredrik Jonson-3 wrote:
> 
> In <25221488.post@talk.nabble.com> tornike wrote:
> 
>>  EntityManager is not thread safe and it should not be injected into the
>>  servlet. (container managed one) However in the example of ejb-JPA 
>> 
>> http://cwiki.apache.org/GMOxDOC21/container-managed-persistence-with-jpa.html
>>
>>  I have tested the example works without problems so are there conditions
>>  when it can be done or am I understanding it the wrong way?
> 
> I'd say the example is wrong or at least careless. So I'm also interested
> if someone thinks otherwise.
> 
> If I would have done it I'd inject a EntityManagerFactory in the servlet
> and
> acquired a new EntityManager from the pool for each request to doGet
> method:
> 
> public class Example extends HttpServlet {
>   @PersistenceUnit
>   private EntityManagerFactory emf;
> 
>   @Override
>   protected void doGet(HttpServletRequest request, HttpServletResponse
> response)
>     throws ServletException, IOException {
>       EntityManager em = emf.createEntityManager();
>       // do stuff
> 
> -- 
> Fredrik Jonson
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/EntityManager---Servlets-tp25221488s134p25226546.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Mime
View raw message