[
https://issues.jboss.org/browse/WFLY-12674?page=com.atlassian.jira.plugin...
]
Scott Marlow updated WFLY-12674:
--------------------------------
Description:
[From related JPA expert group
discussion|https://download.oracle.com/javaee-archive/jpa-spec.java.net/u...]:
{code}
>>>> Perhaps a clearer proposal could be:
>>>>
>>>> "
>>>> If the entity manager is invoked outside the scope of a transaction,
>>>> any entities loaded from the database will
>>>> immediately become detached at the end of the container level method
>>>> invocation call (e.g. when the session bean method
>>>> ends).
>>>> "
>>>
>>> Ah, thanks. That is not the intended semantics. Rather it is that the
>>> persistence context is created to service the method call that is made
>>> on the entity manager only. It doesn't have the duration of a business
>>> method invocation.
>>
>> Is it really?
>>
>
> Yes. See also section 3.8.7, which is quite explicit with regard to
> queries.
> BTW, these decisions date back to JPA 1.0 (aka EJB 3.0).
My updated proposal for the 7.6.2 wording is:
"
If the entity manager is invoked outside the scope of a transaction, any entities loaded
from the database will
immediately become detached at the end of the entity manager method call.
"
OK, sure + "... or query invocation"
{code}
Note that we missed Linda's response of "... or query invocation" in the JPA
spec update, as the JPA 2.2 spec today states:
{quote}
7.6.2 Container-managed Transaction-scoped Persistence Context
The application can obtain a container-managed entity manager with transaction-scoped
persistence context by injection or direct lookup in the JNDI namespace. The persistence
context type for the entity manager is defaulted or defined as
PersistenceContextType.TRANSACTION.
A new persistence context begins when the container-managed entity manager is invoked [84]
in the scope of an active JTA transaction, and there is no current persistence context
already associated with the JTA transaction. The persistence context is created and then
associated with the JTA transaction. This association of the persistence context with the
JTA transaction is independent of the synchronization type of the persistence context and
whether the persistence context has been joined to the transaction.
{quote}
[Some related AS5/6 JPA container
code.|https://anonsvn.jboss.org/repos/jbossas/projects/jpa/trunk/impl/src...]
which simply cleared the persistence context as we were creating a new Query, for example
see:
{code}
public Query createQuery(String ejbqlString)
{
EntityManager em = getEntityManager();
detachEntitiesIfNoTx(em);
return em.createQuery(ejbqlString);
}
{code}
was:
[From related JPA expert group
discussion|https://download.oracle.com/javaee-archive/jpa-spec.java.net/u...]:
{code}
[jpa-spec users] [jsr338-experts] Re: changes for 7.6.2 Container-managed
Transaction-scoped Persistence Context
This message: [ Message body ] [ More options (top, bottom) ]
Related messages: [ Next message ] [ Previous message ] [ In reply to ] [ Next in
thread ] [ Replies ]
Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [
by messages with attachments ]
From: Linda DeMichiel <linda.demichiel_at_oracle.com>
Date: Tue, 29 Nov 2011 15:48:53 -0800
On 11/29/2011 12:15 PM, Scott Marlow wrote:
On 11/29/2011 02:19 PM, Linda DeMichiel wrote:
>
>
> On 11/29/2011 11:06 AM, Scott Marlow wrote:
>> Hi Linda,
>>
>>>
>>> Perhaps I am failing to grasp your concern here, but I see the intention
>>> of the last
>>> paragraph of section 7.6.2 as specifying the user-visible behavior that
>>> is required
>>> to result. Your paragraph above describes a possible implementation
>>> strategy to
>>> achieve it, but I don't think the spec needs to include that.
>>>
>>
>>
>> I think that the current 7.6.2 wording "detached at the end of the
>> method call", is ambiguous about which method call is
>> intended (the entity manager method invocation or the container level
>> method invocation.)
>>
>> I think that clarifying it with one of the following changes, would
>> eliminate the ambiguity.
>>
>> Updated proposal for last paragraph in 7.6.2:
>>
>> "
>> If the entity manager is invoked outside the scope of a transaction,
>> any entities loaded from the database will
>> immediately become detached at the end of the container level method
>> invocation call.
>> "
>
> Just to be very clear.... What are you referring to by "container level
> method
> invocation call"? The call to the entity manager proxy?
Not the call to the entity manager proxy. I mean the code that is calling the entity
manager proxy (e.g. a session bean
calling the entity manager proxy.)
Perhaps a clearer proposal could be:
"
If the entity manager is invoked outside the scope of a transaction, any entities loaded
from the database will
immediately become detached at the end of the container level method invocation call
(e.g. when the session bean method
ends).
"
Ah, thanks. That is not the intended semantics. Rather it is that the
persistence context is created to service the method call that is made
on the entity manager only. It doesn't have the duration of a business
method invocation.
>
> thanks,
>
> -Linda
>
>
>>
>> Regards,
>> Scott
{code}
[Some related AS5/6 JPA container
code.|https://anonsvn.jboss.org/repos/jbossas/projects/jpa/trunk/impl/src...]
placeholder for deferDetach issue
---------------------------------
Key: WFLY-12674
URL:
https://issues.jboss.org/browse/WFLY-12674
Project: WildFly
Issue Type: Task
Components: JPA / Hibernate
Reporter: Scott Marlow
Assignee: Scott Marlow
Priority: Major
[From related JPA expert group
discussion|https://download.oracle.com/javaee-archive/jpa-spec.java.net/u...]:
{code}
>>>>> Perhaps a clearer proposal could be:
>>>>>
>>>>> "
>>>>> If the entity manager is invoked outside the scope of a
transaction,
>>>>> any entities loaded from the database will
>>>>> immediately become detached at the end of the container level
method
>>>>> invocation call (e.g. when the session bean method
>>>>> ends).
>>>>> "
>>>>
>>>> Ah, thanks. That is not the intended semantics. Rather it is that the
>>>> persistence context is created to service the method call that is made
>>>> on the entity manager only. It doesn't have the duration of a
business
>>>> method invocation.
>>>
>>> Is it really?
>>>
>>
>> Yes. See also section 3.8.7, which is quite explicit with regard to
>> queries.
>> BTW, these decisions date back to JPA 1.0 (aka EJB 3.0).
>
> My updated proposal for the 7.6.2 wording is:
>
> "
> If the entity manager is invoked outside the scope of a transaction, any entities
loaded from the database will
> immediately become detached at the end of the entity manager method call.
> "
OK, sure + "... or query invocation"
{code}
Note that we missed Linda's response of "... or query invocation" in the
JPA spec update, as the JPA 2.2 spec today states:
{quote}
7.6.2 Container-managed Transaction-scoped Persistence Context
The application can obtain a container-managed entity manager with transaction-scoped
persistence context by injection or direct lookup in the JNDI namespace. The persistence
context type for the entity manager is defaulted or defined as
PersistenceContextType.TRANSACTION.
A new persistence context begins when the container-managed entity manager is invoked
[84] in the scope of an active JTA transaction, and there is no current persistence
context already associated with the JTA transaction. The persistence context is created
and then associated with the JTA transaction. This association of the persistence context
with the JTA transaction is independent of the synchronization type of the persistence
context and whether the persistence context has been joined to the transaction.
{quote}
[Some related AS5/6 JPA container
code.|https://anonsvn.jboss.org/repos/jbossas/projects/jpa/trunk/impl/src...]
which simply cleared the persistence context as we were creating a new Query, for example
see:
{code}
public Query createQuery(String ejbqlString)
{
EntityManager em = getEntityManager();
detachEntitiesIfNoTx(em);
return em.createQuery(ejbqlString);
}
{code}
--
This message was sent by Atlassian Jira
(v7.13.8#713008)