From open-jpa-dev-return-2617-apmail-incubator-open-jpa-dev-archive=incubator.apache.org@incubator.apache.org Mon Mar 05 17:05:13 2007 Return-Path: Delivered-To: apmail-incubator-open-jpa-dev-archive@locus.apache.org Received: (qmail 90852 invoked from network); 5 Mar 2007 17:05:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Mar 2007 17:05:12 -0000 Received: (qmail 53769 invoked by uid 500); 5 Mar 2007 17:05:20 -0000 Delivered-To: apmail-incubator-open-jpa-dev-archive@incubator.apache.org Received: (qmail 53741 invoked by uid 500); 5 Mar 2007 17:05:20 -0000 Mailing-List: contact open-jpa-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: open-jpa-dev@incubator.apache.org Delivered-To: mailing list open-jpa-dev@incubator.apache.org Received: (qmail 53729 invoked by uid 99); 5 Mar 2007 17:05:20 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2007 09:05:20 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of plinskey@bea.com designates 66.248.192.21 as permitted sender) Received: from [66.248.192.21] (HELO usremg01.bea.com) (66.248.192.21) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2007 09:05:09 -0800 Received: from usremr02.bea.com (usremr02.bea.com [10.160.29.92]) by usremg01.bea.com (Switch-3.2.2/Switch-3.2.2) with ESMTP id l25H4krx027898 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 5 Mar 2007 09:04:50 -0800 Received: from repbex02.amer.bea.com (repbex02.bea.com [10.160.26.99]) by usremr02.bea.com (Switch-3.2.2/Switch-3.2.2) with ESMTP id l25H4cYR031865; Mon, 5 Mar 2007 09:04:38 -0800 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: Entity manager injection Date: Mon, 5 Mar 2007 09:04:40 -0800 Message-ID: <7D856CDFE035FF45A0420ACBD71BDD630366E8D1@repbex02.amer.bea.com> In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Entity manager injection Thread-Index: AcdfRgRPVOxmnVmFRGawdJJ5mNwP8QAAcUVg References: <7D856CDFE035FF45A0420ACBD71BDD630366E892@repbex02.amer.bea.com> From: "Patrick Linskey" To: Cc: X-PMX-Version: 4.7.1.128075, Antispam-Engine: 2.5.0.283055, Antispam-Data: 2007.2.21.151434 X-Virus-Checked: Checked by ClamAV on apache.org > We're managing our own transactions using our=20 > TransactionManager provided through "openjpa.ManagedRuntime".=20 > So I guess we'll have to go for your second solution. I'll=20 > probably implement a simple ThreadLocal holding the=20 > EntityManager associated with the current tx.=20 Hmm. I believe that you actually fall into the first category -- OpenJPA only uses the ManagedRuntime when it thinks that it's integrating with JTA. It sounds like you're using JTA to control transactions, and plugging into OpenJPA SPIs to tell OpenJPA about how to bind into JTA. > Btw it's just an idea but wouldn't it be possible for OpenJPA=20 > to handle persistence manager injection even outside of an=20 > EJB container? It seems to me that all the necessary hooks=20 > exist. Just an idea though :)=20 The hooks certainly do exist, for the most part. However, we already have an API-based way to do this -- OpenJPAPersistence.getEntityManager(Object). Since injecting an instance's EntityManager not quite the same as what happens with the @PersistenceContext annotation from a Java EE standpoint, I prefer to recommend the proprietary OpenJPA extension API. This makes it more clear where you are depending on OpenJPA-specific features, and avoids any semantic confusion. -Patrick --=20 Patrick Linskey BEA Systems, Inc.=20 _______________________________________________________________________ Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.=20 > -----Original Message----- > From: Matthieu Riou [mailto:matthieu.riou@gmail.com]=20 > Sent: Monday, March 05, 2007 8:48 AM > To: Patrick Linskey > Cc: open-jpa-dev@incubator.apache.org > Subject: Re: Entity manager injection >=20 > We're managing our own transactions using our=20 > TransactionManager provided through "openjpa.ManagedRuntime".=20 > So I guess we'll have to go for your second solution. I'll=20 > probably implement a simple ThreadLocal holding the=20 > EntityManager associated with the current tx.=20 >=20 > Btw it's just an idea but wouldn't it be possible for OpenJPA=20 > to handle persistence manager injection even outside of an=20 > EJB container? It seems to me that all the necessary hooks=20 > exist. Just an idea though :)=20 >=20 > Thanks for the help, > Matthieu >=20 >=20 > On 3/5/07, Patrick Linskey wrote: >=20 > Hi, > =09 > IIRC, you're doing something like so: > =09 > @Entity > public class Foo { > @PersistenceContext private EntityManager em; > ... > } > =09 > The Java EE spec's support for resource injection does=20 > not apply for=20 > entity types. So, from an EJB standpoint, you can only=20 > use resource > injection in session beans and MDBs. You're getting the=20 > NPE because your > EJB container ignores the @PersistenceContext=20 > annotation on your entity.=20 > (Note that OpenJPA doesn't do anything at all with=20 > @PersistenceContext > annotations.) > =09 > If you were using a session bean, then there are two=20 > possible answers to > your question: > =09 > 1. If you are managing your own transactions using JTA=20 > and bean-managed=20 > transactions, then you'd be in good shape using=20 > @PersistenceContext. > =09 > 2. If you are managing your own transactions using the JPA > EntityTransaction API, then you cannot use=20 > @PersistenceContext to inject > an EM, but instead must use @PersistenceUnit to inject an > EntityManagerFactory (or some other EMF lookup means),=20 > and do your own > lifecycle management. > =09 > -Patrick > =09 > -- > Patrick Linskey > BEA Systems, Inc.=20 > =09 > =09 > ______________________________________________________________ > _________ > Notice: This email message, together with any=20 > attachments, may contain > information of BEA Systems, Inc., its subsidiaries =20 > and affiliated=20 > entities, that may be confidential, proprietary, =20 > copyrighted and/or > legally privileged, and is intended solely for the use=20 > of the individual > or entity named in this message. If you are not the=20 > intended recipient,=20 > and have received this message in error, please=20 > immediately return this > by email and then delete it. > =09 > > -----Original Message----- > > From: Matthieu Riou [mailto: matthieu.riou@gmail.com=20 > ] > > Sent: Friday, March 02, 2007 8:32 AM > > To: open-jpa-dev@incubator.apache.org > > Subject: Entity manager injection > >=20 > > Hi, > > > > For ODE we're managing our transactions ourselves. We start > > them and commit > > them explicitly. By the same token we create the=20 > EntityManagerFactory > > ourselves. Is there a possibility to use the EntityManager=20 > > injection in the > > persistent classes in this context or do we have to=20 > implement our own > > ThreadLocal based thingy to have the EM available in our > > persistent classes > > using it? > >=20 > > I've tried doing something like: > > > > 1. Adding "@PersistenceContext private EntityManager _em;" > > in a persistence > > class. > > 2. Load the persistence class from an EntityManager=20 > created with the=20 > > factory. > > 3. Use _em in my persistent class > > =3D> NullPointerException > > > > Thanks, > > Matthieu > > > =09 >=20 >=20 >=20