Return-Path: Delivered-To: apmail-incubator-open-jpa-dev-archive@locus.apache.org Received: (qmail 72236 invoked from network); 25 Apr 2007 04:56:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Apr 2007 04:56:48 -0000 Received: (qmail 26773 invoked by uid 500); 25 Apr 2007 04:56:55 -0000 Delivered-To: apmail-incubator-open-jpa-dev-archive@incubator.apache.org Received: (qmail 26740 invoked by uid 500); 25 Apr 2007 04:56:55 -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 26730 invoked by uid 99); 25 Apr 2007 04:56:55 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Apr 2007 21:56:55 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [208.97.132.207] (HELO spaceymail-a2.g.dreamhost.com) (208.97.132.207) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Apr 2007 21:56:47 -0700 Received: from [192.168.15.104] (cpe-76-167-174-30.socal.res.rr.com [76.167.174.30]) by spaceymail-a2.g.dreamhost.com (Postfix) with ESMTP id 191AE106256 for ; Tue, 24 Apr 2007 21:56:27 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: <7D856CDFE035FF45A0420ACBD71BDD630401B2F1@repbex02.amer.bea.com> References: <0552F4DC-B386-4968-8F39-C7061EF2D9AF@iq80.com> <18ECF84F-2C22-41F4-8ECD-CFA9C3B636FA@apache.org> <41603240-33BC-4B51-91AA-ABDADE6BF80A@iq80.com> <7D856CDFE035FF45A0420ACBD71BDD630401B2F1@repbex02.amer.bea.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <9E5C8D48-C713-4BFF-8955-456D36F784F1@iq80.com> Content-Transfer-Encoding: 7bit From: Dain Sundstrom Subject: Re: Set query params without TX? Date: Tue, 24 Apr 2007 21:56:20 -0700 To: open-jpa-dev@incubator.apache.org X-Mailer: Apple Mail (2.752.3) X-Virus-Checked: Checked by ClamAV on apache.org Man, I'm dumb. This code is the EntityManager wrapper for the Container managed EMs (which I wrote so long ago don't remember it). So how is this supposed to work in our container managed EM? The method looks like this: public Query createNamedQuery(String name) { EntityManager entityManager = getEntityManager(); try { return entityManager.createNamedQuery(name); } finally { closeIfNoTx(entityManager); } } So if there is no tx are we supposed to leave the EntityManager open? I'm confused because it seems like I'm supposed to close the em, but if I do the I can't set parameters on the query. -dain On Apr 24, 2007, at 7:31 PM, Patrick Linskey wrote: >>>> at org.apache.openjpa.persistence.EntityManagerImpl.close >>>> (EntityManagerImpl.java:999) >> >> 3) OpenJPA calls em.close since there is no transaction, >> which I think "closes" the query >> >>>> at org.apache.openejb.persistence.JtaEntityManager.closeIfNoTx >>>> (JtaEntityManager.java:87) >> >> 2) OpenJPA calls closeIfNoTx >> >>>> at >>>> org.apache.openejb.persistence.JtaEntityManager.createNamedQuery >>>> (JtaEntityManager.java:189) >> >> 1) OpenEJB calls createNamedQuery >> >>>> at org.apache.openejb.core.cmp.jpa.JpaCmpEngine.createNamedQuery >>>> (JpaCmpEngine.java:287) > > JtaEntityManager is one of your classes, not one of ours. > closeIfNoTx is > your method, not ours. Punk. > > -Patrick > > -- > Patrick Linskey > BEA Systems, Inc. > ______________________________________________________________________ > _ > 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. > >> -----Original Message----- >> From: Dain Sundstrom [mailto:dain@iq80.com] >> Sent: Tuesday, April 24, 2007 7:29 PM >> To: open-jpa-dev@incubator.apache.org >> Subject: Re: Set query params without TX? >> >> I am "they", the one writing the cmp code in OpenEJB. >> >> On first read of the stack trace I thought as you that, I was >> the one close the entity manager, but on a second read I >> notice it was OpenJPA calling "closeIfNoTx" that closes the broker. >> >>> On Apr 24, 2007, at 7:02 PM, Dain Sundstrom wrote: >>> >>>> java.lang.IllegalStateException >>>> at >> org.apache.openjpa.kernel.BrokerImpl.free(BrokerImpl.java:4083) >>>> at >> org.apache.openjpa.kernel.BrokerImpl.close(BrokerImpl.java:4013) >>>> at org.apache.openjpa.kernel.DelegatingBroker.close >>>> (DelegatingBroker.java:1284) >>>> at org.apache.openjpa.persistence.EntityManagerImpl.close >>>> (EntityManagerImpl.java:999) >> >> 3) OpenJPA calls em.close since there is no transaction, >> which I think "closes" the query >> >>>> at org.apache.openejb.persistence.JtaEntityManager.closeIfNoTx >>>> (JtaEntityManager.java:87) >> >> 2) OpenJPA calls closeIfNoTx >> >>>> at >>>> org.apache.openejb.persistence.JtaEntityManager.createNamedQuery >>>> (JtaEntityManager.java:189) >> >> 1) OpenEJB calls createNamedQuery >> >>>> at org.apache.openejb.core.cmp.jpa.JpaCmpEngine.createNamedQuery >>>> (JpaCmpEngine.java:287) >>>> at org.apache.openejb.core.cmp.jpa.JpaCmpEngine.queryBeans >>>> (JpaCmpEngine.java:218) >>>> at org.apache.openejb.core.cmp.CmpContainer.findEJBObject >>>> (CmpContainer.java:718) >>>> at org.apache.openejb.core.cmp.CmpContainer.invoke >>>> (CmpContainer.java:286) >>>> >>>> -dain >>>> >>>> On Apr 24, 2007, at 3:07 PM, Marc Prud'hommeaux wrote: >>>> >>>>> Dain- >>>>> >>>>> Can you send the embedded exception as well? That should >> tell us who >>>>> closed the query, and it might give us a hint why... >>>>> >>>>> >>>>> On Apr 24, 2007, at 3:03 PM, Dain Sundstrom wrote: >>>>> >>>>>> I have some code that runs outside of a transaction which does >>>>>> basically the following: >>>>>> >>>>>> Query query = entityManager.createNamedQuery(name) >>>>>> query.setParameter(1, "foo"); >>>>>> List results = query.getResultList(); >>>>>> >>>>>> If I don't set the parameter the code works fine (assuming the >>>>>> query didn't need a parameter), but when I set the >> parameter, I get >>>>>> the following exception: >>>>>> >>>>>> Caused by: <0.9.7-incubating-SNAPSHOT fatal user error> >>>>>> org.apache.openjpa.persistence.InvalidStateException: >> The context >>>>>> has been closed. The stack trace at which the context >> was closed >>>>>> is held in the embedded exception. >>>>>> FailedObject: java.lang.IllegalStateException >>>>>> at org.apache.openjpa.kernel.BrokerImpl.assertOpen >>>>>> (BrokerImpl.java:4283) >>>>>> at org.apache.openjpa.kernel.QueryImpl.assertOpen >>>>>> (QueryImpl.java:1613) >>>>>> at org.apache.openjpa.kernel.DelegatingQuery.assertOpen >>>>>> (DelegatingQuery.java:626) >>>>>> at org.apache.openjpa.persistence.QueryImpl.setParameter >>>>>> (QueryImpl.java:404) >>>>>> at org.apache.openjpa.persistence.QueryImpl.setParameter >>>>>> (QueryImpl.java:49) >>>>>> at org.apache.openejb.core.cmp.jpa.JpaCmpEngine.executeQuery >>>>>> (JpaCmpEngine.java:261) >>>>>> >>>>>> Is this supposed to work? If not, maybe we should throw the >>>>>> exception when getting the query. >>>>>> >>>>>> In the mean time I'll code around this. >>>>>> >>>>>> -dain >>>>> >>>> >>> >> >> > > 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.