OpenJPA
  1. OpenJPA
  2. OPENJPA-1853

iSeries DB2 problem with using @GeneratedValue(strategy=GenerationType.IDENTITY)

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0.0, 2.0.1
    • Fix Version/s: 2.1.0
    • Component/s: sql
    • Labels:
      None
    • Environment:
      DB2 on IBM iSeries V5R4, jt400.jar (JTOpen)

      Description

      I get the following error when I try to insert new row to a table that has a "generated always Identity" Column.

      Exception in thread "main" <openjpa-2.0.1-r422266:989424 fatal store error> org.apache.openjpa.persistence.RollbackException: An error occurred attempting to invoke JDBC 3 method. Your driver or database may not support JDBC 3 features.
      at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:584)
      at de.meyerwerft.qs.laborpruef.laborprobe.dbaccess.LaborprobeBean.crtTest(LaborprobeBean.java:38)
      at de.meyerwerft.test.JSE_Client.jlm_run(JSE_Client.java:35)
      at de.meyerwerft.test.JSE_Client.<init>(JSE_Client.java:10)
      at de.meyerwerft.test.JSE_Client.main(JSE_Client.java:17)
      Caused by: <openjpa-2.0.1-r422266:989424 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: An error occurred attempting to invoke JDBC 3 method. Your driver or database may not support JDBC 3 features.
      at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1963)
      at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
      at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1479)
      at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:925)
      at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:560)
      ... 4 more
      Caused by: org.apache.commons.lang.exception.NestableRuntimeException: An error occurred attempting to invoke JDBC 3 method. Your driver or database may not support JDBC 3 features.
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.invokeJDBC3(DelegatingConnection.java:597)
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:577)
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.prepareStatement(LoggingConnectionDecorator.java:571)
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:571)
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:571)
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:563)
      at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.prepareStatement(PreparedStatementManagerImpl.java:287)
      at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:112)
      at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:81)
      at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:99)
      at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:87)
      at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550)
      at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:106)
      at org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
      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:731)
      at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
      at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2139)
      at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2037)
      at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1955)
      ... 8 more
      Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.invokeJDBC3(DelegatingConnection.java:593)
      ... 28 more
      Caused by: java.sql.SQLException: The driver does not support this function.
      at com.ibm.as400.access.JDError.throwSQLException(JDError.java:415)
      at com.ibm.as400.access.AS400JDBCConnection.prepareStatement(AS400JDBCConnection.java:2210)
      ... 33 more

      I have the following in persistence.xml
      ...
      <property name="openjpa.jdbc.DBDictionary" value="db2"/>
      <property name="openjpa.ConnectionDriverName" value="com.ibm.as400.access.AS400JDBCDriver"/>
      <property name="openjpa.ConnectionURL" value="jdbc:as400://myserver/myschema"/>
      ...

      In Version 1.2.3 this function works fine.

      Thank you,
      Andreas Tomik

        Activity

        Hide
        Jeremy Bauer added a comment -

        Hi Andreas. I've been looking at what looks to be the same issue - identity column id, iSeries toolbox driver with 2.1.0 snapshot, but haven't yet been able to reproduce it outside of an app server environment. It looks to be caused by some odd sql getting generated. If you could post a simple JSE test that would really help things along.

        Show
        Jeremy Bauer added a comment - Hi Andreas. I've been looking at what looks to be the same issue - identity column id, iSeries toolbox driver with 2.1.0 snapshot, but haven't yet been able to reproduce it outside of an app server environment. It looks to be caused by some odd sql getting generated. If you could post a simple JSE test that would really help things along.
        Hide
        Andreas Tomik added a comment - - edited

        Hi Jeremy,
        i attached a simple JSE Test. I hope this helps you.
        Please do not hesitate to contact me if you have any further questions.

        Show
        Andreas Tomik added a comment - - edited Hi Jeremy, i attached a simple JSE Test. I hope this helps you. Please do not hesitate to contact me if you have any further questions.
        Hide
        Jeremy Bauer added a comment -

        Thanks so much for the test code. I'll give it a try and let you know what I find.

        Show
        Jeremy Bauer added a comment - Thanks so much for the test code. I'll give it a try and let you know what I find.
        Hide
        Jeremy Bauer added a comment -

        Unfortunately, your test ran successfully on my system. The iSeries is at OS level V7R1 though. I'm trying to get access to a V5R4 system. Could you run on your system with toolbox jdbc trace turned on and post the output? There may be some clues in there.

        <property name="openjpa.ConnectionURL" value="jdbc:as400://myserver/myschema;trace=true;toolbox trace=jdbc"/>

        In addition, what type of entity enhancement are you using? The javaagent?

        Show
        Jeremy Bauer added a comment - Unfortunately, your test ran successfully on my system. The iSeries is at OS level V7R1 though. I'm trying to get access to a V5R4 system. Could you run on your system with toolbox jdbc trace turned on and post the output? There may be some clues in there. <property name="openjpa.ConnectionURL" value="jdbc:as400://myserver/myschema;trace=true;toolbox trace=jdbc"/> In addition, what type of entity enhancement are you using? The javaagent?
        Hide
        Jeremy Bauer added a comment -

        In OpenJPA 2.x, a JDBC 3.0 enhancement for returning auto generated keys from a prepared statement was enabled by default based upon the JDBC driver level. I've found that the toolbox driver running against a V5R4 system does not support this functionality on the server side. This function does exist on the server side on V7R1 (and possibly V6), but only seems to work with the non-XA driver. That's why I've been having issues only in an app server environment running against a V7R1 server.

        The good news is that there's a simple workaround. Adding this property to your persistence.xml will go back to the "old way" of doing business.

        <property name="openjpa.jdbc.DBDictionary" value="db2(supportsGetGeneratedKeys=false)"/>

        I'll work on a code fix that checks the iSeries version in addition to the JDBC driver level and possibly whether the driver is XA (if that turns out to be a limitation rather than a bug) to determine how this value should be set.

        Show
        Jeremy Bauer added a comment - In OpenJPA 2.x, a JDBC 3.0 enhancement for returning auto generated keys from a prepared statement was enabled by default based upon the JDBC driver level. I've found that the toolbox driver running against a V5R4 system does not support this functionality on the server side. This function does exist on the server side on V7R1 (and possibly V6), but only seems to work with the non-XA driver. That's why I've been having issues only in an app server environment running against a V7R1 server. The good news is that there's a simple workaround. Adding this property to your persistence.xml will go back to the "old way" of doing business. <property name="openjpa.jdbc.DBDictionary" value="db2(supportsGetGeneratedKeys=false)"/> I'll work on a code fix that checks the iSeries version in addition to the JDBC driver level and possibly whether the driver is XA (if that turns out to be a limitation rather than a bug) to determine how this value should be set.
        Hide
        Jeremy Bauer added a comment -

        Auto generated keys are supported with OS V6R1 and later. Although, toolbox/JTOpen appears to have a bug in this area when using an XA data source, but it won't affect non-XA users. The JTOpen developers have been notified of the the XA issue and have been provided a simple test case to reproduce the problem.

        A simple change was committed to 2.1.x/trunk under revision 1027250 that reverts back to the OpenJPA 1.x.x method of getting generated ids for V5R4 and prior OS levels.

        Show
        Jeremy Bauer added a comment - Auto generated keys are supported with OS V6R1 and later. Although, toolbox/JTOpen appears to have a bug in this area when using an XA data source, but it won't affect non-XA users. The JTOpen developers have been notified of the the XA issue and have been provided a simple test case to reproduce the problem. A simple change was committed to 2.1.x/trunk under revision 1027250 that reverts back to the OpenJPA 1.x.x method of getting generated ids for V5R4 and prior OS levels.
        Hide
        Jeremy Bauer added a comment -

        Please verify that this problem is corrected in trunk/2.1.0 as of the noted revision.

        Show
        Jeremy Bauer added a comment - Please verify that this problem is corrected in trunk/2.1.0 as of the noted revision.

          People

          • Assignee:
            Jeremy Bauer
            Reporter:
            Andreas Tomik
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development