aries-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Schneider (JIRA)" <>
Subject [jira] [Resolved] (ARIES-1083) Create either a synchronised entity manager or a proxy which creates an entity manager for each request
Date Fri, 17 Jul 2015 08:17:05 GMT


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:
>             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(

>         at org.hibernate.loader.Loader.initializeEntitiesAndCollections(

>         at org.hibernate.loader.Loader.processResultSet( 
>         at org.hibernate.loader.Loader.doQuery( 
>         at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(

>         at org.hibernate.loader.Loader.doList( 
>         at org.hibernate.loader.Loader.doList( 
>         at org.hibernate.loader.Loader.listIgnoreQueryCache( 
>         at org.hibernate.loader.Loader.list( 
>         at org.hibernate.loader.hql.QueryLoader.list( 
>         at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(

>         at org.hibernate.engine.query.spi.HQLQueryPlan.performList(

>         at org.hibernate.internal.SessionImpl.list( 
>         at org.hibernate.internal.QueryImpl.list( 
> 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
> 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

View raw message