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:

        at org.apache.openjpa.kernel.BrokerImpl.close(
at org.apache.openjpa.kernel.DelegatingBroker.close ( at org.apache.openjpa.persistence.EntityManagerImpl.close ( at org.apache.openejb.persistence.JtaEntityManager.closeIfNoTx ( at org.apache.openejb.persistence.JtaEntityManager.createNamedQuery ( at org.apache.openejb.core.cmp.jpa.JpaCmpEngine.createNamedQuery ( at org.apache.openejb.core.cmp.jpa.JpaCmpEngine.queryBeans ( at org.apache.openejb.core.cmp.CmpContainer.findEJBObject ( at org.apache.openejb.core.cmp.CmpContainer.invoke (


On Apr 24, 2007, at 3:07 PM, Marc Prud'hommeaux wrote:


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 ( at org.apache.openjpa.kernel.QueryImpl.assertOpen( 1613) at org.apache.openjpa.kernel.DelegatingQuery.assertOpen ( at org.apache.openjpa.persistence.QueryImpl.setParameter ( at org.apache.openjpa.persistence.QueryImpl.setParameter ( at org.apache.openejb.core.cmp.jpa.JpaCmpEngine.executeQuery (

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.


Reply via email to