users@glassfish.java.net

UserTransaction for JPA During the whole web request

From: <glassfish_at_javadesktop.org>
Date: Tue, 23 Feb 2010 00:29:21 PST

Hi,
I have J2EE 6 Web Application which contain EJB inside the WAR (great feature) that expose as RESTful web service.

One of the resource methods load an EntityBean from the EJB session and then access a OneToMany relation.

Currently I get a LazyInitializationException since I mark that relation as lazy and glassfish close the EntityManager.

1. How can I leave the UserTransaction open for the duration of the request and thus having the EntityManage stay alive to load the lazy collections? (I used to accomplish that using a custom servlet that call begin() method of UserTransaction when the service() method started and call commit or rollback when it ends.

2. What is the best practice here? I can't find any articles about how to handle real world RESTful web application that involve more than customer and orders.

Thank you,
Ido
[Message sent by forum member 'ido_ran' (ido.ran_at_gmail.com)]

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