Topic
10 replies Latest Post - ‏2014-03-18T19:55:19Z by mhamann
SachinP
SachinP
1 Post
ACCEPTED ANSWER

Pinned topic WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

‏2011-05-06T07:45:06Z |
Hi,
We are using WAS 7.0.0.9 with JPA 2.0 Feature pack installed on Windows environment. In process of trying a simple operation of persisting a Entity, we get the following exception;

Caused by: <openjpa-2.0.0-r422266:935683 fatal general error> org.apache.openjpa.persistence.PersistenceException: Invalid cursor name.
FailedObject: prepstmnt 1380602442 INSERT INTO EMP_REG (EMP_ID, REG_TIME) VALUES (?, ?) http://org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement_
at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4827)
at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4787)
at org.apache.openjpa.jdbc.sql.DB2Dictionary.newStoreException(DB2Dictionary.java:563)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:78)
at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushBatch(BatchingPreparedStatementManagerImpl.java:232)
at org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:63)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:103)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:751)
at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
... 43 more
Caused by: com.ibm.db2.jcc.b.SqlException: Invalid cursor name.
at com.ibm.db2.jcc.b.zc.setCursorName(zc.java:723)
at com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper.doStatementCleanup(DB2UniversalDataStoreHelper.java:240)
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.closeWrapper(WSJdbcPreparedStatement.java:491)
at com.ibm.ws.rsadapter.jdbc.WSJccPreparedStatement.closeWrapper(WSJccPreparedStatement.java:290)
at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:240)
at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:193)
at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.close(DelegatingPreparedStatement.java:155)
at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.close(DelegatingPreparedStatement.java:155)
at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushBatch(BatchingPreparedStatementManagerImpl.java:230)
... 48 more

The Entity EmpRegistrationMaster that we want to persist has two attribute;
empID and regTime. The empID is a db generated sequence number to be inserted with each record.

Following is the definition of EmpRegistrationMaster entity class;

@Entity
@Table(name="EMP_REG")
@SequenceGenerator(name="EmpRegSeq", sequenceName="EMP_REG_SEQ")

public class EmpRegistrationMaster implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="EmpRegSeq")
@Column(name = "EMP_ID",nullable=false,length=25)
private int empID;

@Column(name="REG_TIME",length=50)
private Date regTime;

Following is the definition of the StatelessSession bean (EmpRegistrationBean) injected with the Entity Manager, used for persisting the entity;

@Stateless

public class EmpRegistrationBean implements EmpRegistration{

@PersistenceContext(unitName="getstarted")
EntityManager em;

@Action(Action.ACTION_TYPE.CREATE)
public int insertEmpReg(EmpRegistrationMaster empReg) throws IllegalStateException,
SecurityException, SystemException
{
int emp_id_inserted=0;
try
{
em.persist(empReg);

}
catch(Exception e)
{
e.printStackTrace();
}
return emp_id_inserted;
}

This same code is working on WAS 7 test environment with JPA 1.0, but not working on WAS 7.0.0.9 for Application Developer env with JPA.20.

Any hints / directions would be helpful.

Thanks in advance.
Updated on 2012-07-24T13:31:55Z at 2012-07-24T13:31:55Z by sutter
  • sutter
    sutter
    93 Posts
    ACCEPTED ANSWER

    Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

    ‏2011-05-06T13:29:57Z  in response to SachinP
    Hi SachinP,
    I agree that your scenario seems pretty straight forward and should be working just fine... I'm going to start with some basic questions and observations and then we'll take it from there.

    o I am assuming that your EMP_REG table does exist. Fair assumption?

    o The length parameter on the @Column annotation only applies to String-based attributes. I would remove them.

    @Column(name = "EMP_ID",nullable=false)
    private int empID;

    @Column(name="REG_TIME")
    private Date regTime;

    o Is there more to this call stack or other messages in the log that might indicate more about this situation (either before or after)?

    o Can you post your persistence.xml?

    Thanks,
    Kevin
    • Maxim--
      Maxim--
      4 Posts
      ACCEPTED ANSWER

      Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

      ‏2012-07-06T04:59:41Z  in response to sutter
      Hi there,

      A year later I've got the same exception, can't figure out what it means. Is there a solution?

      I'm using WebSphere 8 and DB2.

      My persistence.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
      version="2.0">
      <persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
      <jta-data-source>jdbc/db2Datasource</jta-data-source>
      <class>com.qbe.config.bean.QBEProperty</class>
      <properties>
      <property name="openjpa.Multithreaded" value="true"/>
      </properties>
      </persistence-unit>
      </persistence>
      The stack trace:

      6/07/12 14:53:46:726 EST 00000021 servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet JAXRSApplication in application QBEMM. Exception created : [<openjpa-2.1.2-SNAPSHOT-r422266:1179900 fatal store error> org.apache.openjpa.persistence.RollbackException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred.
      FailedObject: prepstmnt 114199888 UPDATE CCHDEVT.TCC_PROPERTY SET COMMENTS = ?, LAST_UPDATED = ? WHERE PROPERTY_NAME = ? http://org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement_
      at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:593)
      at com.qbe.config.dao.GenericDAOJpaImpl.update(GenericDAOJpaImpl.java:51)
      at com.qbe.config.service.QBEPropertyService.saveProperty(QBEPropertyService.java:42)
      at com.qbe.config.web.QBEPropertyResource.save(QBEPropertyResource.java:87)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:611)
      at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
      at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$VoidOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:167)
      at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
      at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
      at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
      at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483)
      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
      at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1188)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:763)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:454)
      at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1020)
      at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3703)
      at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
      at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
      at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
      at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
      at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1659)
      Caused by: <openjpa-2.1.2-SNAPSHOT-r422266:1179900 fatal general error> org.apache.openjpa.persistence.PersistenceException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred.
      FailedObject: prepstmnt 114199888 UPDATE CCHDEVT.TCC_PROPERTY SET COMMENTS = ?, LAST_UPDATED = ? WHERE PROPERTY_NAME = ? http://org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement_
      at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2321)
      at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2158)
      at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2056)
      at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1974)
      at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
      at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1498)
      at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:933)
      at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:569)
      ... 45 more
      Caused by: <openjpa-2.1.2-SNAPSHOT-r422266:1179900 fatal general error> org.apache.openjpa.persistence.PersistenceException: Invalid cursor name.
      FailedObject: prepstmnt 114199888 UPDATE CCHDEVT.TCC_PROPERTY SET COMMENTS = ?, LAST_UPDATED = ? WHERE PROPERTY_NAME = ? http://org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement_
      at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4878)
      at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4838)
      at org.apache.openjpa.jdbc.sql.DB2Dictionary.newStoreException(DB2Dictionary.java:596)
      at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
      at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:78)
      at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushBatch(BatchingPreparedStatementManagerImpl.java:236)
      at org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:63)
      at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:103)
      at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:742)
      at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
      ... 52 more
      Caused by: com.ibm.db2.jcc.a.SqlException: Invalid cursor name.
      at com.ibm.db2.jcc.a.zc.setCursorName(zc.java:723)
      at com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper.doStatementCleanup(DB2UniversalDataStoreHelper.java:243)
      at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.closeWrapper(WSJdbcPreparedStatement.java:490)
      at com.ibm.ws.rsadapter.jdbc.WSJccPreparedStatement.closeWrapper(WSJccPreparedStatement.java:294)
      at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:240)
      at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:193)
      at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.close(DelegatingPreparedStatement.java:161)
      at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.close(DelegatingPreparedStatement.java:161)
      at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushBatch(BatchingPreparedStatementManagerImpl.java:234)
      ... 57 more
      ]

      Thanks!
      • sutter
        sutter
        93 Posts
        ACCEPTED ANSWER

        Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

        ‏2012-07-09T14:52:32Z  in response to Maxim--
        Hi Maxim--,
        Sorry you are still experiencing the issue after moving up to WAS v8... Based on a quick review of your persistence.xml, why are you using this property?

        <property name="openjpa.Multithreaded" value="true"/>

        Granted, it's a valid property from an OpenJPA perspective, but if you feel you are required to use it, then you should re-evaluate your application. EntityManagers, by the spec, are not meant to be shared across threads. This property is really used to just diagnose multi-threaded usage. If removing this property or setting it to "false" introduces some issues in your application, then those issues should be resolved before moving on.

        This multi-threaded access could also be the reason behind your "invalid cursor" error. You could be accidentally re-using an EntityManager that has already been closed, or at least the corresponding transaction has been completed.

        That's where I would focus my energies. Good luck!

        Kevin Sutter, JPA Architect, IBM WebSphere
        • Maxim--
          Maxim--
          4 Posts
          ACCEPTED ANSWER

          Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

          ‏2012-07-11T02:13:03Z  in response to sutter
          Hi Kevin,

          Thanks for replying!

          I wrote the DAO using jUnit tests and hibernate and the tests were passing. But after creating a web app where a servlet (JAXRS resource actually) used the dao and testing it on WAS8 I had an error saying "Multiple thread access detected, set openjpa.Multithreaded to true". So I did. I then made my DAO fully synchronized but the property in persistence.xml still remained. I've removed the property, now my property.xml looks like this:

          <?xml version="1.0" encoding="UTF-8"?>
          <persistence xmlns="http://java.sun.com/xml/ns/persistence"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
          version="2.0">
          <persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
          <jta-data-source>jdbc/db2Datasource</jta-data-source>
          <class>com.qbe.config.bean.QBEProperty</class>
          </persistence-unit>
          </persistence>

          But I'm still getting the

          Caused by: com.ibm.db2.jcc.a.SqlException: Invalid cursor name.
          at com.ibm.db2.jcc.a.zc.setCursorName(zc.java:723)
          at com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper.doStatementCleanup(DB2UniversalDataStoreHelper.java:243)
          at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.closeWrapper(WSJdbcPreparedStatement.java:490)
          at com.ibm.ws.rsadapter.jdbc.WSJccPreparedStatement.closeWrapper(WSJccPreparedStatement.java:294)

          Trace diagnostics for jcc show that setCursorName on prepared statement passes null as the argument:
          ibmdb2jccTime:1341972031892Thread:WebContainer : 0ResultSet@6b15fe2 next () returned false
          ibmdb2jccTime:1341972031892Thread:WebContainer : 0ResultSet@6b15fe2 close () called
          ibmdb2jccTime:1341972031892Thread:WebContainer : 0PreparedStatement@6b0e6fe getMoreResults () called
          ibmdb2jccTime:1341972031892Thread:WebContainer : 0PreparedStatement@6b0e6fe getMoreResults () returned false
          ibmdb2jccTime:1341972031892Thread:WebContainer : 0PreparedStatement@6b0e6fe getUpdateCount () called
          ibmdb2jccTime:1341972031892Thread:WebContainer : 0PreparedStatement@6b0e6fe getUpdateCount () returned -1
          ibmdb2jccTime:1341972031892Thread:WebContainer : 0PreparedStatement@6b0e6fe setCursorName (null) called
          ibmdb2jcc BEGIN TRACE_DIAGNOSTICS
          ibmdb2jccSQLException@706cf42 java.sql.SQLException
          ibmdb2jccSQLException@706cf42 SQL state = null
          ibmdb2jccSQLException@706cf42 Error code = -99999
          ibmdb2jccSQLException@706cf42 Message = Invalid cursor name.
          ibmdb2jccSQLException@706cf42 Stack trace follows
          com.ibm.db2.jcc.a.SqlException: Invalid cursor name.
          at com.ibm.db2.jcc.a.zc.setCursorName(zc.java:723)
          at com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper.doStatementCleanup(DB2UniversalDataStoreHelper.java:243)
          at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.closeWrapper(WSJdbcPreparedStatement.java:490)
          at com.ibm.ws.rsadapter.jdbc.WSJccPreparedStatement.closeWrapper(WSJccPreparedStatement.java:294)
          at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:240)
          at com.ibm.ws.rsadapter.jdbc.WSJdbcObject.close(WSJdbcObject.java:193)
          at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.close(DelegatingPreparedStatement.java:161)
          at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.close(DelegatingPreparedStatement.java:161)
          • sutter
            sutter
            93 Posts
            ACCEPTED ANSWER

            Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

            ‏2012-07-11T16:27:47Z  in response to Maxim--
            HI Maxim--,
            That's good that you were able to remove the "Multithreaded=true" property relatively easy. On the unfortunate side, it didn't seem to help with the diagnosis of your issue...

            I'm still guessing it's a timing issue, which makes debugging this type of problem all the more difficult.

            Have you tried turning on the openjpa tracing? If you can still reproduce the problem with this tracing turned on then it might show some error condition that happens earlier that is affecting the processing of the connection later. You can turn this on via the following property in your p.xml:

            <property name="openjpa.Log" value="DefaultLevel=TRACE"/>

            It looks like you are hitting the issue while procesing some batched statements. Although the statement causing the issue is dumped, maybe we're not getting the whole context of the exception due to the batching. As another type of test, maybe you could turn batching off just to see if affects the processing in anyway (you could do this change in conjunction with the Tracing request):

            <property name="openjpa.jdbc.DBDictionary" value="db2(batchLimit=0)"/>

            The other thing that you could do that might generate more dedicated support is to open a PMR. You could reference this discussion via URL for background information. At least by going this approach, if a code change is required, an APAR would be easily created. If you want to continue this discussion via the forum until we get closer to a conclusion that's fine with me as well...

            Good luck,
            Kevin Sutter, JPA Architect, IBM WebSphere
            • Maxim--
              Maxim--
              4 Posts
              ACCEPTED ANSWER

              Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

              ‏2012-07-13T07:28:58Z  in response to sutter
              Hi Kevin,

              It worked after setting db2(batchLimit=0)! Insert, delete, update, all fine no problems. I did open a PMR and I'm in contact with a support analyst but I guess we might still carry on here as well so that people who will find this article after googling for the same problem will have a better picture? So the batchLimit=0 fixed the symptoms and my application is functional. Removing the property for setting batch limit to 0 and adding a property for tracing produced the following error in the log:

              13/07/12 17:08:00:751 EST 00000020 SystemErr R 10359 manager1 TRACE WebContainer : 2 openjpa.Runtime - Trying datasource1
              13/07/12 17:08:00:751 EST 00000020 SystemErr R 10375 manager1 TRACE WebContainer : 2 openjpa.Runtime - Found datasource1: datasource -956987833 from configuration. StoreContext: com.ibm.ws.persistence.kernel.WsJpaBrokerImpl@7477d1f
              13/07/12 17:08:00:751 EST 00000020 SystemErr R 10375 manager1 TRACE WebContainer : 2 openjpa.Runtime - com.ibm.ws.persistence.EntityManagerFactoryImpl@807b866 created EntityManager com.ibm.ws.persistence.EntityManagerImpl@7477d1f.
              13/07/12 17:08:00:766 EST 00000020 SystemErr R 10390 manager1 INFO WebContainer : 2 openjpa.Runtime - WebSphere persistence provider access intent function initialzed.
              13/07/12 17:08:00:782 EST 00000021 SystemErr R 10406 manager1 TRACE WebContainer : 3 openjpa.jdbc.SQL - <t 122126377, conn 121898193> 78 ms spent
              13/07/12 17:08:00:860 EST 00000020 SystemErr R 10484 manager1 TRACE WebContainer : 2 openjpa.jdbc.SQL - <t 121923946, conn 122350646> executing prepstmnt 122364408 SELECT t0.COMMENTS, t0.LAST_UPDATED, t0.UPDATED_BY, t0.PROPERTY_VALUE FROM CCHDEVT.TCC_PROPERTY t0 WHERE t0.PROPERTY_NAME = ? optimize for 1 row params=?
              13/07/12 17:08:00:876 EST 00000020 SystemErr R 10500 manager1 TRACE WebContainer : 2 openjpa.jdbc.SQL - <t 121923946, conn 122350646> 16 ms spent
              13/07/12 17:08:00:891 EST 00000020 SystemErr R 10515 manager1 TRACE WebContainer : 2 openjpa.jdbc.JDBC - <t 121923946, conn 122350646> 0 ms close
              13/07/12 17:08:00:938 EST 00000020 SystemErr R 10562 manager1 TRACE WebContainer : 2 openjpa.jdbc.SQLDiag - flush: org.apache.openjpa.kernel.PDirtyState for oid=test.maxim.propname
              13/07/12 17:08:00:938 EST 00000020 SystemErr R 10562 manager1 TRACE WebContainer : 2 openjpa.jdbc.JDBC - The batch limit is set to 100.
              13/07/12 17:08:00:954 EST 00000020 SystemErr R 10578 manager1 TRACE WebContainer : 2 openjpa.jdbc.SQL - <t 121923946, conn 122825422> executing prepstmnt 122915858 UPDATE CCHDEVT.TCC_PROPERTY SET COMMENTS = ?, LAST_UPDATED = ? WHERE PROPERTY_NAME = ? params=?, ?, ?
              13/07/12 17:08:04:501 EST 0000001e SystemErr R 14125 manager1 TRACE WebContainer : 0 openjpa.jdbc.JDBC - <t 121916955, conn 117624973> 0 ms close
              13/07/12 17:08:04:501 EST 0000001e SystemErr R 14125 manager1 TRACE WebContainer : 0 openjpa.Runtime - com.ibm.ws.persistence.EntityManagerImpl@6ccb09d.close() invoked.
              13/07/12 17:08:07:923 EST 00000020 SystemErr R 17547 manager1 TRACE WebContainer : 2 openjpa.jdbc.SQL - <t 121923946, conn 122825422> 6969 ms spent
              13/07/12 17:08:07:938 EST 00000021 SystemErr R 17562 manager1 TRACE WebContainer : 3 openjpa.jdbc.JDBC - <t 122126377, conn 121898193> 0 ms close
              13/07/12 17:08:07:938 EST 00000021 SystemErr R 17562 manager1 TRACE WebContainer : 3 openjpa.Runtime - com.ibm.ws.persistence.EntityManagerImpl@7422a6e.close() invoked.
              13/07/12 17:08:07:938 EST 00000020 SystemErr R 17562 manager1 TRACE WebContainer : 2 openjpa.Runtime - An exception occurred while ending the transaction. This exception will be re-thrown.
              <openjpa-2.1.2-SNAPSHOT-r422266:1179900 fatal store error> org.apache.openjpa.util.StoreException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred.
              FailedObject: prepstmnt 122915858 UPDATE CCHDEVT.TCC_PROPERTY SET COMMENTS = ?, LAST_UPDATED = ? WHERE PROPERTY_NAME = ? http://org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement_
              at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2321)
              at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2158)
              at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2056)
              And in the system out there's just this:

              13/07/12 17:07:50:641 EST 00000021 ConnectionFac W J2CA0294W: Direct JNDI lookup of resource jdbc/cchangeDatasource. The following default values are used:
              Resource-ref CMConfigData key items

              res-sharing-scope: 0 (SHAREABLE)
              res-isolation-level: 0 (TRANSACTION_NONE)
              res-auth: 1 (APPLICATION)
              isCMP1_x: false (not CMP1.x)
              isJMS: false (not JMS)
              commitPriority 0
              branchCoupling -1
              loginConfigurationName: null
              loginConfigProperties: null
              Resource ref name: not set

              Resource-ref non-key items

              J2EE Name: QBEMM#config.war#JAXRSApplication
              isCMP: false (not set)
              isWar: true (looked-up component was a War module)

              And in db2 jcc trace log file there's this:

              ibmdb2jccTime:1342163287923Thread:WebContainer : 2PreparedStatement@7538a86 clearParameters () called
              ibmdb2jccTime:1342163287923Thread:WebContainer : 3PreparedStatement@7447578 close () called
              ibmdb2jccTime:1342163287923Thread:WebContainer : 2PreparedStatement@7538a86 getMoreResults () called
              ibmdb2jccTime:1342163287923Thread:WebContainer : 2PreparedStatement@7538a86 getMoreResults () returned false
              ibmdb2jccTime:1342163287923Thread:WebContainer : 2PreparedStatement@7538a86 getUpdateCount () called
              ibmdb2jccTime:1342163287923Thread:WebContainer : 2PreparedStatement@7538a86 getUpdateCount () returned -1
              ibmdb2jccTime:1342163287923Thread:WebContainer : 2PreparedStatement@7538a86 setCursorName (null) called
              ibmdb2jcc BEGIN TRACE_DIAGNOSTICS
              ibmdb2jccSQLException@7515d3b java.sql.SQLException
              ibmdb2jccSQLException@7515d3b SQL state = null
              ibmdb2jccSQLException@7515d3b Error code = -99999
              ibmdb2jccSQLException@7515d3b Message = Invalid cursor name.
              ibmdb2jccSQLException@7515d3b Stack trace follows
              com.ibm.db2.jcc.a.SqlException: Invalid cursor name.
              at com.ibm.db2.jcc.a.zc.setCursorName(zc.java:723)
              at com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper.doStatementCleanup(DB2UniversalDataStoreHelper.java:243)
              at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.closeWrapper(WSJdbcPreparedStatement.java:490)
              The only thing I can sport is this line
              ibmdb2jccTime:1342163287923Thread:WebContainer : 2PreparedStatement@7538a86 setCursorName (null) called

              Would be interesting to find what exactly is causing it, if you can see that Kevin?
              Thanks a lot for suggesting the "db2(batchLimit=0)" at least now I've got a fully functioning app, which is major progress already.

              Maxim
              • sutter
                sutter
                93 Posts
                ACCEPTED ANSWER

                Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

                ‏2012-07-13T21:13:06Z  in response to Maxim--
                Great news, Maxim, that you are making progress!

                Unfortunately, it doesn't look like Tracing provided any additional details with batching turned on. But, it does show that EntityManagers are being closed... Are you using application-managed persistence (where your application controls the lifecycle of the EMF and EM), or are you using container-managed persistence (where you allow the container to manage the lifecycle)? If the former, have you been able to verify that you are not accidentally closing an EM before the transaction has completed? Normally, this shouldn't be allowed, but since you originally had some multi-threaded issues, maybe there's still something lurking?

                Another idea would be to systematically increase the BatchLimit to see where the issue arises. I'd start simple with 1, then 2, then make bigger jumps. If you do this with Trace turned on, then hopefully that would shed some light on which statement batch and which SQL statements are causing the issue. Turning BatchLimit to 0 is probably just allowing your application to avoid the window where this connection/cursor is getting closed. My guess is that the problem still exists with BatchLimit turned off, but you haven't hit it yet.

                Good luck with the debugging! I am out on vacation next week, so I would try to work this problem through the PMR process. If you make progress, please post back to the forum. I have also asked my team to help monitor this forum in my absence, but some of these people are also working the PMR queue. So, there's no need to double up on IBM help if you are getting it from one location or the other...

                Thanks,
                Kevin Sutter, JPA Architect, IBM WebSphere
                • Maxim--
                  Maxim--
                  4 Posts
                  ACCEPTED ANSWER

                  Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

                  ‏2012-07-16T06:46:34Z  in response to sutter
                  Hi Kevin,

                  EntityManagers were indeed being created and closed right before and right after every transaction because I wanted to see if closing entity manager would make any difference, which it didn't. Now the code looks like this: a DaoFactory creates a DAO which is a singleton, the dao is instantiated with EntityManagerFactory which is used once to create EntityManager. So at all times there's only one instance of the DAO with one instance of EntityManager. Every public method of the DAO is synchronized.

                  I've tried increasing the batch limit setting and the error appears as soon as it's set to 2. There are no errors if it's 0 or 1 and there's always the error if it's 2 or more.

                  Thanks for your help Kevin and have a great vacation!

                  Maxim.
                  • sutter
                    sutter
                    93 Posts
                    ACCEPTED ANSWER

                    Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

                    ‏2012-07-24T13:31:55Z  in response to Maxim--
                    Hi Maxim,
                    Did you make any further progress while I was out? What is the PMR number for the issue? I'd like to check on it to see what kind of progress is being made. Thanks.

                    I'd like to summarize your situation to see if we're on the same page... If you set the BatchLimit to either 0 or 1, your application is working just fine. As soon as you bump this up to 2 or more batched statements, then the problem comes back. Is that correct? And, if that is correct, are you experiencing any other issues when the BatchLimit is 0 or 1?

                    The other question I have concerns your description of your DAO. Am I understanding correctly that you create a new EMF with each DAO? Or, are you passing in an existing EMF when instantiating the DAO? If it's the former, then you have a performance concern that should be addressed. Creating EMFs are very expensive and should be limited.

                    Thanks,
                    Kevin Sutter, JPA Architect, IBM WebSphere
                  • mhamann
                    mhamann
                    1 Post
                    ACCEPTED ANSWER

                    Re: WAS 7.0.0.9 + JPA 2.0 Feature pack - Invalid cursor name.

                    ‏2014-03-18T19:55:19Z  in response to Maxim--

                    Maxim, did you ever solve this? I've been seeing the same issue.