You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Dain Sundstrom <da...@iq80.com> on 2007/04/25 00:03:57 UTC

Set query params without TX?

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

RE: Set query params without TX?

Posted by Patrick Linskey <pl...@bea.com>.
> 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:plinskey@bea.com] 
> 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:dain@iq80.com]
> > 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.

RE: Set query params without TX?

Posted by Patrick Linskey <pl...@bea.com>.
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:dain@iq80.com] 
> 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.

Re: Set query params without TX?

Posted by Dain Sundstrom <da...@iq80.com>.
Is a query a one time use object?  Meaning, I only get to call  
getResultList(), getSingleResult(), or executeUpdate() once and then  
I have to get a new instance.

Also you stated:

On Apr 24, 2007, at 10:35 PM, Patrick Linskey wrote:
> (please please please make it a dynamic
> proxy that implements all the interfaces that the proxied thing
> implements).

When I first wrote the proxy, I tried to implement it using a dymanic  
proxy, but gave up after I discovered the extreme differences in the  
handling of the methods.  Some methods require an active transaction,  
and some are fine without one, but you have to close the em in a  
finally block.  The getQuery methods, need to have the Query object  
proxied, but only if there is no transaction. Some methods like  
joinTransaction(), close(), isOpen(), and getTransaction() just have  
custom rules.

So I could easily create a dynamic proxy, but which strategy would I  
choose for the methods that are "dyanmic" (i.e., the extra methods  
not on the entity manager interface)?

-dain

Re: Set query params without TX?

Posted by Dain Sundstrom <da...@iq80.com>.
On Apr 25, 2007, at 10:22 AM, Patrick Linskey wrote:

>> If I want to have generic code, how am I supposed to
>> implement the createNamedQuery method?  Do I leave the EM
>> open forever?  That doesn't seem right.  So when am I
>> supposed to close the EM?
>
> 1. Create an EM proxy. You've already got one, so we're good there.
>
> 2. The EM proxy should create a new EM for each persistence  
> context. In
> a tx, that means that it hangs onto the EM for the duration of the tx.
> Outside a tx, that means that it keeps the EM open for the duration of
> each operation.
>
> For a find(), that's the duration of the stack execution.
>
> For a query, that means you need to create a Query proxy also, and  
> hand
> off the EM created during createQuery() to the Query proxy. Then, the
> Query proxy is responsible for closing the EM after
> Query.getResultList() / Query.getSingleResult() is exectued.

Ah. That is my problemo.

Thanks,

-dain

RE: Set query params without TX?

Posted by Patrick Linskey <pl...@bea.com>.
> If I want to have generic code, how am I supposed to 
> implement the createNamedQuery method?  Do I leave the EM 
> open forever?  That doesn't seem right.  So when am I 
> supposed to close the EM?

1. Create an EM proxy. You've already got one, so we're good there.

2. The EM proxy should create a new EM for each persistence context. In
a tx, that means that it hangs onto the EM for the duration of the tx.
Outside a tx, that means that it keeps the EM open for the duration of
each operation. 

For a find(), that's the duration of the stack execution. 

For a query, that means you need to create a Query proxy also, and hand
off the EM created during createQuery() to the Query proxy. Then, the
Query proxy is responsible for closing the EM after
Query.getResultList() / Query.getSingleResult() is exectued.

-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: Wednesday, April 25, 2007 10:04 AM
> To: open-jpa-dev@incubator.apache.org
> Subject: Re: Set query params without TX?
> 
> On Apr 24, 2007, at 10:35 PM, Patrick Linskey wrote:
> 
> > Yep -- you've gotta keep it open. If you want to support 
> any JPA impl, 
> > you need to have an EM proxy (please please please make it 
> a dynamic 
> > proxy that implements all the interfaces that the proxied thing 
> > implements).
> 
> That code is from my proxy.
> 
> > If you're happy tying yourself to OpenJPA (or if you want 
> to optimize 
> > for OpenJPA), then you can use the openjpa.AutoDetach 
> property to tell 
> > OpenJPA how to handle non-transactional work. In that scenario, you 
> > can keep a single EM per your delegating instance, and rely 
> on OpenJPA 
> > to do the transactional PC semantics.
> 
> I just might give that a try.
> 
> If I want to have generic code, how am I supposed to 
> implement the createNamedQuery method?  Do I leave the EM 
> open forever?  That doesn't seem right.  So when am I 
> supposed to close the EM?
> 
> -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.

Re: Set query params without TX?

Posted by Dain Sundstrom <da...@iq80.com>.
On Apr 24, 2007, at 10:35 PM, Patrick Linskey wrote:

> Yep -- you've gotta keep it open. If you want to support any JPA impl,
> you need to have an EM proxy (please please please make it a dynamic
> proxy that implements all the interfaces that the proxied thing
> implements).

That code is from my proxy.

> If you're happy tying yourself to OpenJPA (or if you want to optimize
> for OpenJPA), then you can use the openjpa.AutoDetach property to tell
> OpenJPA how to handle non-transactional work. In that scenario, you  
> can
> keep a single EM per your delegating instance, and rely on OpenJPA  
> to do
> the transactional PC semantics.

I just might give that a try.

If I want to have generic code, how am I supposed to implement the  
createNamedQuery method?  Do I leave the EM open forever?  That  
doesn't seem right.  So when am I supposed to close the EM?

-dain

RE: Set query params without TX?

Posted by Patrick Linskey <pl...@bea.com>.
Yep -- you've gotta keep it open. If you want to support any JPA impl,
you need to have an EM proxy (please please please make it a dynamic
proxy that implements all the interfaces that the proxied thing
implements).

If you're happy tying yourself to OpenJPA (or if you want to optimize
for OpenJPA), then you can use the openjpa.AutoDetach property to tell
OpenJPA how to handle non-transactional work. In that scenario, you can
keep a single EM per your delegating instance, and rely on OpenJPA to do
the transactional PC semantics.

-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 9:56 PM
> To: open-jpa-dev@incubator.apache.org
> Subject: Re: Set query params without TX?
> 
> 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.
> 
> 

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.

Re: Set query params without TX?

Posted by Dain Sundstrom <da...@iq80.com>.
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.


Re: Set query params without TX?

Posted by Marc Prud'hommeaux <mp...@apache.org>.
> closeIfNoTx is your method, not ours. Punk.

FTR, Patrick means that in the nicest possible way :)




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.


RE: Set query params without TX?

Posted by Patrick Linskey <pl...@bea.com>.
> >> 	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.

Re: Set query params without TX?

Posted by Dain Sundstrom <da...@iq80.com>.
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
>>>
>>
>


Re: Set query params without TX?

Posted by Marc Prud'hommeaux <mp...@apache.org>.
It looks like openejb is closing the EntityManager while creating the  
query for some reason. You might want to check with them to see why  
they might be doing this.

Might they be prohibiting you from running at all outside of the  
transaction?


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)
> 	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
>>
>


Re: Set query params without TX?

Posted by Dain Sundstrom <da...@iq80.com>.
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
>


Re: Set query params without TX?

Posted by Marc Prud'hommeaux <mp...@apache.org>.
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


RE: Set query params without TX?

Posted by Patrick Linskey <pl...@bea.com>.
> Is this supposed to work?  If not, maybe we should throw the 
> exception when getting the query.

This should be legal. The execution of the query will return data in a
new persistence context (i.e., immediately detached), but you definitely
should be able to set parameters in a PCType=TRANSACTIONAL environment.

-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 3:04 PM
> To: open-jpa-dev@incubator.apache.org
> Subject: Set query params without TX?
> 
> 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.