Return-Path: X-Original-To: apmail-aries-dev-archive@www.apache.org Delivered-To: apmail-aries-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4DF5617835 for ; Fri, 17 Jul 2015 08:17:06 +0000 (UTC) Received: (qmail 24753 invoked by uid 500); 17 Jul 2015 08:17:05 -0000 Delivered-To: apmail-aries-dev-archive@aries.apache.org Received: (qmail 24701 invoked by uid 500); 17 Jul 2015 08:17:05 -0000 Mailing-List: contact dev-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list dev@aries.apache.org Received: (qmail 24421 invoked by uid 99); 17 Jul 2015 08:17:05 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jul 2015 08:17:05 +0000 Date: Fri, 17 Jul 2015 08:17:05 +0000 (UTC) From: "Christian Schneider (JIRA)" To: dev@aries.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Resolved] (ARIES-1083) Create either a synchronised entity manager or a proxy which creates an entity manager for each request MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ 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)