[ 
https://issues.apache.org/jira/browse/ARIES-1083?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Christian Schneider resolved ARIES-1083.
----------------------------------------
       Resolution: Fixed
         Assignee: Christian Schneider
    Fix Version/s: jpa-2.0.0

In Aries JPA 2 the EntityManagers are stored per thread now. So this should not 
happen anymore.

> Create either a synchronised entity manager or a proxy which creates an 
> entity manager for each request
> -------------------------------------------------------------------------------------------------------
>
>                 Key: ARIES-1083
>                 URL: https://issues.apache.org/jira/browse/ARIES-1083
>             Project: Aries
>          Issue Type: Improvement
>          Components: JPA
>    Affects Versions: jpa-container-context-1.0.1
>            Reporter: Joe Qiang Luo
>            Assignee: Christian Schneider
>             Fix For: jpa-2.0.0
>
>
> When using Apache Aries (container managed Transactions, JTA) with Hibernate 
> for persistence, if we start multiple threads to read from the database 
> without transactions (Transaction Annotation is ommited), we get the 
> following stacktrace:
> org.hibernate.AssertionFailure: possible non-threadsafe access to the session 
>         at 
> org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:130)
>  
>         at 
> org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1103)
>  
>         at org.hibernate.loader.Loader.processResultSet(Loader.java:960) 
>         at org.hibernate.loader.Loader.doQuery(Loader.java:910) 
>         at 
> org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
>  
>         at org.hibernate.loader.Loader.doList(Loader.java:2516) 
>         at org.hibernate.loader.Loader.doList(Loader.java:2502) 
>         at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332) 
>         at org.hibernate.loader.Loader.list(Loader.java:2327) 
>         at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490) 
>         at 
> org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
>  
>         at 
> org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
>  
>         at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1247) 
>         at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) 
> The reason we got this exception in a non-transacted mode is that we inject 
> EntityManager in our implementation and use it for different requests from 
> multiple threads. Unfortunately, the EntityManager is not thread safe and we 
> have to refactor the code to inject EntityManagerFactory instead since 
> EntityManagerFactory is thread safe and then create EntityManagers in each 
> method programmatically.
> From Aries stand point, we should be able to improve it in order to ease the 
> pain by creating a synchronized entity manager, or a proxy which creates 
> entity managers for each request. And the proxy would probably do the 
> following:
> 1. create EntityManager;
> 2. perform request;
> 3. close EntityManager;



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to