aries-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Luo (JIRA)" <>
Subject [jira] [Created] (ARIES-1083) Create either a synchronised entity manager or a proxy which creates an entity manager for each request
Date Wed, 19 Jun 2013 14:13:21 GMT
Joe Luo created ARIES-1083:

             Summary: Create either a synchronised entity manager or a proxy which creates
an entity manager for each request
                 Key: ARIES-1083
             Project: Aries
          Issue Type: Improvement
          Components: JPA
    Affects Versions: jpa-container-context-1.0.1
            Reporter: Joe Luo

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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message