I am running into hibernate exceptions because of lazy-loaded collections in
a jax-rs application.

The entities are loaded during Resource.handle() and the collections are
being requested
during the write of the MessageBodyWriter.

When I implement 'OpenSessionInView' as a restlet Filter the session is
already closed when the representation is streamed.

When I implement it as a ConnectorService (inspired by this thread
http://www.mail-archive.com/discuss@restlet.tigris.org/msg07220.html)
I run into a similar problem, namely that there is no
TransactionSynchronizationManager during Resource.handle(), and hence
that the sesion available during streaming is a different one (and hence, I
still get lazy initialization problems).

I could open the Hibernate session in a Filter.beforeHandle and close it in
the connector.afterHandle, but that seems dangerous for leaking sessions
(when Resource.handle() throws an exception ConnectorService.afterSend() is
not called).
Is there an API with 'before' and 'after' calls which span both the
Resource.handle and the MessageBodyWriter.write?

Regards,
Karel

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2696325

Reply via email to