users@jpa-spec.java.net

[jpa-spec users] Re: Is it allowed for SFSB to return extended EntityManager to clients?

From: Arne Limburg <arne.limburg_at_openknowledge.de>
Date: Tue, 29 Jan 2013 10:02:48 +0000

Hi all,


Good issue from Donatas. I stumbled over this, too, some time ago and I
would like to extend the question:
When an entity was loaded from an extended persistence context that is
bound to a stateful session bean. Is lazy loading supposed to work outside
of the call stack of that stateful session bean, i.e. in a JSF managed
bean or a cdi bean that is directly accessed via EL?
I think it was Jboss AS 7 with Hibernate where this did not work.

Regards,
Arne

Am 29.01.13 10:56 schrieb "donatas.ciuksys_at_mif.vu.lt" unter
<donatas.ciuksys_at_mif.vu.lt>:

>Dear JPA experts,
>
>Could you please clarify, whether it is allowed for stateful session
>bean having container-managed extended persistence context to return
>
>its EntityManager to clients (and for clients to perform operations on
>this EntityManager), or is it forbidden?
>
>Currently, GlassFish allows returning the extended EntityManager to
>outside (e.g. http://java.net/jira/browse/GLASSFISH-11805), Apache
>OpenEJB does not, and there is currently ongoing discussion about issue
>https://issues.apache.org/jira/browse/TOMEE-509 .
>
>JPA 2.0 specification had following text (stars added by me):
>
>-----------------------------------------------
>3.3 Persistence Context Lifetime
>...
>When an extended persistence context is used, the extended persistence
>context exists from the time the
>EntityManager instance is created until it is closed. This persistence
>context might span multiple transactions
>and non-transactional invocations of the EntityManager. A
>container-managed extended persistence
>context is enlisted in the current transaction when *the EntityManager
>is invoked in the scope of
>that transaction* or when the stateful session bean to which the
>extended persistence context is bound is
>invoked in the scope of that transaction.
>-----------------------------------------------
>
>The part between ³*² seems to suggest, that EntityManager could be
>accessed by some external entity directly, not necessarily through
>
>stateful session bean method.
>I cannot find this text in JPA 2.1 public draft though.
>
>Question: can reference to extended EntityManager be provided to
>outside, and methods called on this reference?
>
>Regards,
>Donatas