Topic
2 replies Latest Post - ‏2011-10-31T14:56:09Z by PKGATTU
PKGATTU
PKGATTU
2 Posts
ACCEPTED ANSWER

Pinned topic OpenJPA 2.0 - Invoking Stored Procedure

‏2011-10-31T12:26:01Z |
I am having problems in invoking the Stored Procedure through OpenJPA. When I tried to invoke the Stored Procedure, I get the following Exceptions (Complete StackTrace given at the end).

Can someone please guide on what is the mistake that is being done here?
I am using my same framework classes for Insert, Update operations and have no problems in using them.

Tried with the following:
1. Checked the Status of the Transaction before I am trying to Begin a new one and found no active transactions.
2. Tried also with getting the java.sql.connection through EntityManager unwrap method but still the same issue.

<openjpa-2.0.2-SNAPSHOT-r422266:1032678 fatal store error> org.apache.openjpa.persistence.OptimisticLockException: Unable to obtain an object lock on "null".
<openjpa-2.0.2-SNAPSHOT-r422266:1032678 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: This operation failed for some instances. See the nested exceptions array for details.
<openjpa-2.0.2-SNAPSHOT-r422266:1032678 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: This operation cannot be performed while a Transaction is active.
Caused by: <openjpa-2.0.2-SNAPSHOT-r422266:1032678 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: This operation cannot be performed while a Transaction is active.

Environment used is given below:
App Server: WAS Base 7.0.0.15
JPA 2.0 Feature 1.0.0.3

Code Snippet
EntityManager em = getEntityManager();
em.getTransaction().begin();
Query query = getEntityManager().createNamedQuery("callMyStoredProc");
int execRes = query.executeUpdate();
em.getTransaction().commit();

In the Entity Class, the code snippet is as follows:
@NamedNativeQuery(name = "callMyStoredProc", query = "call my_pkg.my_stored_prc()")
Exception Stack trace
10/31/11 17:11:28:101 IST 00000016 SystemOut O > Exception occured: <openjpa-2.0.2-SNAPSHOT-r422266:1032678 fatal store error> org.apache.openjpa.persistence.OptimisticLockException: Unable to obtain an object lock on "null".
10/31/11 17:11:28:101 IST 00000016 SystemOut O > Exception occured: MyCustomException: <openjpa-2.0.2-SNAPSHOT-r422266:1032678 fatal store error> org.apache.openjpa.persistence.OptimisticLockException: Unable to obtain an object lock on "null".
10/31/11 17:11:28:101 IST 00000016 servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: Uncaught exception created in one of the service methods of the servlet FeedbackFileConfigTest in application Test1EAR. Exception created : <openjpa-2.0.2-SNAPSHOT-r422266:1032678 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: This operation failed for some instances. See the nested exceptions array for details.
at org.apache.openjpa.kernel.AbstractBrokerFactory.assertNoActiveTransaction(AbstractBrokerFactory.java:705)
at org.apache.openjpa.kernel.AbstractBrokerFactory.close(AbstractBrokerFactory.java:383)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.close(DelegatingBrokerFactory.java:197)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.close(EntityManagerFactoryImpl.java:267)
at My Invoking class line number

Caused by: <openjpa-2.0.2-SNAPSHOT-r422266:1032678 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: This operation cannot be performed while a Transaction is active.
FailedObject: com.ibm.ws.persistence.EntityManagerImpl@78407840
at org.apache.openjpa.kernel.AbstractBrokerFactory.assertNoActiveTransaction(AbstractBrokerFactory.java:700)
... 26 more

10/31/11 17:11:28:101 IST 00000016 LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
10/31/11 17:11:28:101 IST 00000016 webapp E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: Servlet Error-FeedbackFileConfigTest: <openjpa-2.0.2-SNAPSHOT-r422266:1032678 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: This operation failed for some instances. See the nested exceptions array for details.
at org.apache.openjpa.kernel.AbstractBrokerFactory.assertNoActiveTransaction(AbstractBrokerFactory.java:705)
at org.apache.openjpa.kernel.AbstractBrokerFactory.close(AbstractBrokerFactory.java:383)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.close(DelegatingBrokerFactory.java:197)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.close(EntityManagerFactoryImpl.java:267)
at My Invoking class line number

Caused by: <openjpa-2.0.2-SNAPSHOT-r422266:1032678 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: This operation cannot be performed while a Transaction is active.
FailedObject: com.ibm.ws.persistence.EntityManagerImpl@78407840
at org.apache.openjpa.kernel.AbstractBrokerFactory.assertNoActiveTransaction(AbstractBrokerFactory.java:700)
... 26 more
Updated on 2011-10-31T14:56:09Z at 2011-10-31T14:56:09Z by PKGATTU
  • sutter
    sutter
    94 Posts
    ACCEPTED ANSWER

    Re: OpenJPA 2.0 - Invoking Stored Procedure

    ‏2011-10-31T13:32:29Z  in response to PKGATTU
    Hi PKGATTU,
    Something is out of sync with the description of the problem. The call stacks all indicate that the issue is starting by calling close() an an EntityManager. But, the code snippets you provided all point at invoking a stored procedure. Can you further connect the dots so that we can see the connection between the stored procedure invocation and the EntityManager being closed?

    Thanks,
    Kevin Sutter, JPA Architect, IBM WebSphere
    • PKGATTU
      PKGATTU
      2 Posts
      ACCEPTED ANSWER

      Re: OpenJPA 2.0 - Invoking Stored Procedure

      ‏2011-10-31T14:56:09Z  in response to sutter
      Sutter, that was a good catch. Thanks for that.

      I was overlooking that the exception was from the close(). My StoredProc invocation had a different exception which got suppressed and was thrown exception in close. Your comment really helped me to further debug it in right way with right exception and I am able to fix it.

      Appreciate your pointers.