Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 63952 invoked from network); 17 Dec 2009 16:21:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Dec 2009 16:21:52 -0000 Received: (qmail 38336 invoked by uid 500); 17 Dec 2009 16:21:52 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 38283 invoked by uid 500); 17 Dec 2009 16:21:51 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 38273 invoked by uid 99); 17 Dec 2009 16:21:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Dec 2009 16:21:51 +0000 X-ASF-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_MED X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [216.82.250.83] (HELO mail120.messagelabs.com) (216.82.250.83) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Dec 2009 16:21:48 +0000 X-VirusChecked: Checked X-Env-Sender: dk068x@att.com X-Msg-Ref: server-2.tower-120.messagelabs.com!1261066886!29235777!1 X-StarScan-Version: 6.2.4; banners=-,-,- X-Originating-IP: [144.160.112.25] Received: (qmail 21388 invoked from network); 17 Dec 2009 16:21:26 -0000 Received: from sbcsmtp3.sbc.com (HELO tlph064.enaf.dadc.sbc.com) (144.160.112.25) by server-2.tower-120.messagelabs.com with DHE-RSA-AES256-SHA encrypted SMTP; 17 Dec 2009 16:21:26 -0000 Received: from enaf.dadc.sbc.com (localhost.localdomain [127.0.0.1]) by tlph064.enaf.dadc.sbc.com (8.14.3/8.14.3) with ESMTP id nBHGLNFL010611 for ; Thu, 17 Dec 2009 10:21:25 -0600 Received: from td03xsmtp005.US.Cingular.Net (td03xspare20-new.us.cingular.net [135.179.64.44] (may be forged)) by tlph064.enaf.dadc.sbc.com (8.14.3/8.14.3) with ESMTP id nBHGLJo7009968 for ; Thu, 17 Dec 2009 10:21:19 -0600 Received: from BD01XSMTP003.US.Cingular.Net ([135.163.18.44]) by td03xsmtp005.US.Cingular.Net with Microsoft SMTPSVC(6.0.3790.3959); Thu, 17 Dec 2009 10:21:19 -0600 Received: from BD01MSXMB018.US.Cingular.Net ([135.214.27.52]) by BD01XSMTP003.US.Cingular.Net with Microsoft SMTPSVC(6.0.3790.3959); Thu, 17 Dec 2009 08:21:18 -0800 x-mimeole: Produced By Microsoft Exchange V6.5 x-cr-puzzleid: {58B1AF07-BBDB-4D11-AED8-3BED4CC54AC0} MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable x-cr-hashedpuzzle: BVBs B6kL CUc6 C8g3 EU5m EsZz F00W F8F+ Gxrw HVl9 ImUj KWYY KXle Kd95 KxFZ Kyik;1;dQBzAGUAcgBzAEAAbwBwAGUAbgBqAHAAYQAuAGEAcABhAGMAaABlAC4AbwByAGcA;Sosha1_v1;7;{58B1AF07-BBDB-4D11-AED8-3BED4CC54AC0};ZABrADAANgA4AHgAQABhAHQAdAAuAGMAbwBtAA==;Thu, 17 Dec 2009 16:21:16 GMT;UgBFADoAIABHAGUAdAAgACIAWQBvAHUAIABjAGEAbgBuAG8AdAAgAGEAYwBjAGUAcwBzACAAdABoAGUAIABFAG4AdABpAHQAeQBUAHIAYQBuAHMAYQBjAHQAaQBvAG4AIAB3AGgAZQBuACAAdQBzAGkAbgBnACAAbQBhAG4AYQBnAGUAZAAgAHQAcgBhAG4AcwBhAGMAdABpAG8AbgBzAC4AIgAgAHcAaABlAG4AIABJACAAaQBtAHAAbABlAG0AZQBuAHQAIABAAFQAcgBhAG4AcwBhAGMAdABpAG8AbgBhAGwAIABtAGUAdABoAG8AZABzACAAdwBpAHQAaAAgAE8AcABlAG4ASgBQAEEA Content-class: urn:content-classes:message Subject: RE: Get "You cannot access the EntityTransaction when using managed transactions." when I implement @Transactional methods with OpenJPA Date: Thu, 17 Dec 2009 08:21:16 -0800 Message-ID: In-Reply-To: <438363DC-ABB6-4068-A4C8-F1CB0D2DDC34@SUN.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Get "You cannot access the EntityTransaction when using managed transactions." when I implement @Transactional methods with OpenJPA Thread-Index: Acp+k+D81Ets9AJlSbyAwZ0sTqdhWAAnpm1Q References: <438363DC-ABB6-4068-A4C8-F1CB0D2DDC34@SUN.com> From: "KARR, DAVID (ATTCINW)" To: X-OriginalArrivalTime: 17 Dec 2009 16:21:18.0382 (UTC) FILETIME=[F67BDCE0:01CA7F34] > -----Original Message----- > From: Craig.Russell@Sun.COM [mailto:Craig.Russell@Sun.COM] > Sent: Wednesday, December 16, 2009 1:07 PM > To: users@openjpa.apache.org > Subject: Re: Get "You cannot access the EntityTransaction when using > managed transactions." when I implement @Transactional methods with > OpenJPA >=20 > Hi, >=20 > There are two transaction models you can use in a Java EE container. > If you use the JTA datasource, you need to use the Java EE transaction > manager. If you use only a non-JTA datasource, you can manage the > transactions using EntityTransaction. >=20 > I don't know the details with regard to integrating with Spring, but > you might be ok with just using the non-JTA datasource in your > environment. If you use the JTA datasource, you need to use the > managed transaction interface (I recall you can look this up as a JNDI > resource). A bunch of things just "came together" at the end of the day yesterday. I'm glad it's working, but I think I need to understand better why it's now working. I'd appreciate any ideas about this. It looks like the last problem I had is that I was setting "non-jta-data-source", and not "jta-data-source", but my "transaction-type" was "JTA". I changed that to "RESOURCE_LOCAL" and my last error went away. In addition, the other problem I had had, where the test case with "categories with child categories" would throw an NPE in "pcReplaceField()", also went away. Throughout all of this, I'm using a DataSource defined in WebLogic, so I can get connection pooling (as opposed to just doing a direct connection). I started out with my Controller layer directly calling my DAO layer, which referenced the EntityManager. That's when I noticed the NPE in "pcReplaceField()" for one of my two existing test cases. At that point I thought perhaps it might be a good idea to implement a transactional layer between the Controller and DAO, even if it was only read-only. I put the "@Transactional" annotation on that service layer method, and that produced the InvalidStateException. After that, I ended up changing "jta-data-source" to "non-jta-data-source" and the "transaction-type" to "RESOURCE_LOCAL". That fixed both problems. Although the OpenJPA doc, JPA spec, and Spring doc mentions "transaction-type", "JTA", and "RESOURCE_LOCAL", neither of them really explain the choices and the real implications and consequences of those choices. On a related topic, if a persistence.xml has "transaction-type" set to "JTA" with no "jta-data-source" setting, is it reasonable to say that there's no way that could work? If so, wouldn't this be a reasonable thing for the framework to validate and present a message in that case? > On Dec 16, 2009, at 8:45 AM, KARR, DAVID (ATTCINW) wrote: >=20 > > I have an app using Spring 2.5.6, OpenJPA 1.2.1, and WebLogic > > 10.3.2. I > > specified a JTA datasource in the persistence.xml. I have a Spring > > controller that calls my DAO class which uses the EntityManager. > This > > is working ok with respect to transactions. As my app is only going > > to > > be reading the database, I would think I wouldn't need transactions. > > However, because of one problem I'm having with traversing an > > association path, I thought I would try to implement a transactional > > service layer, and do the association walking within that layer. > > > > So, I added a class with a "@Transactional" method and put that in > > between the Controller and the DAO. Now, I'm seeing the following > > exception stack trace: > > > > -------------------- > > Caused by: > > org.springframework.transaction.CannotCreateTransactionException: > > Could > > not open JPA EntityManager for transaction; nested exception is > > > > org.apache.openjpa.persistence.InvalidStateException: You cannot > > access > > the EntityTransaction when using managed transactions. > > at > > org > > .springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransaction > > Manager.java:375) > > at > > org > > .springframework.transaction.support.AbstractPlatformTransactionManag > > er.getTransaction(AbstractPlatformTransactionManager.java:374) > > at > > org > > .springframework.transaction.interceptor.TransactionAspectSupport.cre > > ateTransactionIfNecessary(TransactionAspectSupport.java:263) > > at > > org > > .springframework.transaction.interceptor.TransactionInterceptor.invok > > e(TransactionInterceptor.java:101) > > at > > org > > .springframework.aop.framework.ReflectiveMethodInvocation.proceed(Ref > > lectiveMethodInvocation.java:171) > > at > > org.springframework.aop.framework.Cglib2AopProxy > > $DynamicAdvisedIntercept > > or.intercept(Cglib2AopProxy.java:635) > > at > > com.att.ecom.dynamiccontent.service.CatalogService$$EnhancerByCGLIB$ > > $5a7 > > c3444.retrieveCatalogTree() > > at > > com.att.ecom.dynamiccontent.content.Content.getCatalog(Content.java: > > 35) > > -------------------- >=20 > Craig L Russell > Architect, Sun Java Enterprise System http://db.apache.org/jdo > 408 276-5638 mailto:Craig.Russell@sun.com > P.S. A good JDO? O, Gasp!