> Alternately, I think that you can rely on OpenJPA's detach > modes to do this for you; instead of actually closing the EM, > just tell OpenJPA to handle detaching when outside a tx.
I meant 'auto detach modes'. I think that 'openjpa.AutoDetach: commit, close, rollback, nontx-read' will do the trick from a transactional persistence context standpoint. I'm not sure if you need close in there. -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: Patrick Linskey [mailto:[EMAIL PROTECTED] > Sent: Tuesday, April 24, 2007 7:26 PM > To: open-jpa-dev@incubator.apache.org > Subject: RE: Set query params without TX? > > Why are you calling close() during createNamedQuery()? > > Turns out that you need to do more work to ensure that the > query doesn't get closed until after it's been executed. This > basically means that you need to have a proxy EM that creates > Query instances that have references to the underlying active EM. > > Alternately, I think that you can rely on OpenJPA's detach > modes to do this for you; instead of actually closing the EM, > just tell OpenJPA to handle detaching when outside a tx. > > -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:[EMAIL PROTECTED] > > Sent: Tuesday, April 24, 2007 7:03 PM > > To: open-jpa-dev@incubator.apache.org > > Subject: Re: Set query params without TX? > > > > 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) > > at org.apache.openejb.persistence.JtaEntityManager.closeIfNoTx > > (JtaEntityManager.java:87) > > at > > org.apache.openejb.persistence.JtaEntityManager.createNamedQuery > > (JtaEntityManager.java:189) > > 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. > 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.