Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-4455

Prepared statement failure with CLOB: Stream has already been read and end-of-file reached and cannot be re-used.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 10.5.3.0
    • 10.5.3.1, 10.6.1.0
    • Network Server
    • None
    • Mac OS X 10.6.2, Java 6, Bitronix JTA
    • Crash, Regression

    Description

      Possibly related to #4332?

      We have encountered an error when using Prepared Statements and CLOBs. I have read:

      http://db.apache.org/derby/papers/JDBCImplementation.html#setAsciiStream%2CsetBinaryStream%2CsetCharacterStream

      But it does not seem applicable, as we are not re-using a stream.

      The environment is this:

      1. Java 6
      2. Derby 10.5.3.0
      3. Bitronix JTA 1.3.3

      We're actually using Hibernate, but I eliminated it from the equation (and the problem persists).

      A summary of the failure flow is this:

      1. Start a transaction
      2. Obtain a connection from a pool of connections (for this test, the pool size is pinned at 1)
      3. Prepare a statement that inserts a CLOB.
      4. Set the parameters
      5. Add the prepared statement to a batch (but we only batch 1 – this is to emulate what hibernate is doing as closely as possible).
      6. Execute the batch.

      Everything up to this point works.

      7. Repeat steps 1-6. But this time, the connection will be reused from the pool, and the statement will be gotten from a prepared statement cache (maintained by bitronix). I.e. the prepared statement is re-used.
      8. Observe the following failure:

      org.apache.derby.client.am.BatchUpdateException: Non-atomic batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements.
      at org.apache.derby.client.am.Agent.endBatchedReadChain(Unknown Source)
      at org.apache.derby.client.am.PreparedStatement.executeBatchRequestX(Unknown Source)
      at org.apache.derby.client.am.PreparedStatement.executeBatchX(Unknown Source)
      at org.apache.derby.client.am.PreparedStatement.executeBatch(Unknown Source)
      at bitronix.tm.resource.jdbc.JdbcPreparedStatementHandle.executeBatch(JdbcPreparedStatementHandle.java:248)
      at org.dancernetworks.TestFailure.doInsert(TestFailure.java:134)
      at org.dancernetworks.TestFailure.doPrepared(TestFailure.java:110)
      at org.dancernetworks.TestFailure.main(TestFailure.java:55)
      Nov 30, 2009 10:29:31 PM bitronix.tm.BitronixTransactionManager shutdown
      INFO: shutting down Bitronix Transaction Manager
      An IOException was thrown when reading a 'java.sql.String' from an InputStream.
      java.sql.SQLException: An IOException was thrown when reading a 'java.sql.String' from an InputStream.
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
      at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown Source)
      at org.apache.derby.impl.jdbc.EmbedPreparedStatement.transferParameters(Unknown Source)
      at org.apache.derby.jdbc.XAStatementControl.getRealPreparedStatement(Unknown Source)
      at org.apache.derby.iapi.jdbc.BrokeredPreparedStatement.getPreparedStatement(Unknown Source)
      at org.apache.derby.iapi.jdbc.BrokeredPreparedStatement.getStatement(Unknown Source)
      at org.apache.derby.iapi.jdbc.BrokeredStatement.close(Unknown Source)
      at org.apache.derby.impl.drda.DRDAStatement.close(Unknown Source)
      at org.apache.derby.impl.drda.Database.close(Unknown Source)
      at org.apache.derby.impl.drda.Session.close(Unknown Source)
      at org.apache.derby.impl.drda.DRDAConnThread.closeSession(Unknown Source)
      at org.apache.derby.impl.drda.DRDAConnThread.run(Unknown Source)
      Caused by: java.sql.SQLException: An IOException was thrown when reading a 'java.sql.String' from an InputStream.
      at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
      ... 15 more
      Caused by: java.sql.SQLException: Java exception: 'Stream has already been read and end-of-file reached and cannot be re-used.: java.io.EOFException'.
      at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
      at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
      ... 12 more
      Caused by: java.io.EOFException: Stream has already been read and end-of-file reached and cannot be re-used.
      at org.apache.derby.iapi.types.ReaderToUTF8Stream.read(Unknown Source)
      at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:320)
      at org.apache.derby.iapi.types.SQLChar.readExternal(Unknown Source)
      at org.apache.derby.iapi.types.SQLChar.getString(Unknown Source)
      at org.apache.derby.iapi.types.SQLChar.setFrom(Unknown Source)
      at org.apache.derby.iapi.types.DataType.setValue(Unknown Source)
      at org.apache.derby.impl.sql.GenericParameterValueSet.transferDataValues(Unknown Source)
      at org.apache.derby.impl.sql.execute.BaseActivation.setParameters(Unknown Source)
      at org.apache.derby.impl.sql.GenericActivationHolder.setParameters(Unknown Source)
      ... 10 more

      Attached is an archived Eclipse project of a self-contained reproduction. It includes everything needed to run, including the Bitronix 1.3.3 jar.

      Attachments

        1. derby-4455-1a.diff
          3 kB
          Kristian Waagan
        2. derby-4455-1b.diff
          3 kB
          Kristian Waagan
        3. derby-4455-1c.diff
          3 kB
          Kristian Waagan
        4. DerbyFailure.zip
          3.24 MB
          Brett Wooldridge
        5. ReproAttemptDerby4455.java
          2 kB
          Katherine Marsden

        Issue Links

          Activity

            People

              kristwaa Kristian Waagan
              brettw Brett Wooldridge
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: