Loading ...
Sorry, an error occurred while loading the content.
 

Batch Update and Blobs

Expand Messages
  • Michael Kaegi
    Hi Jaybird Developers I m using Hibernate 3.2 + Jaybird 2.1.1 + Firebird 1.5 In hibernate I try to save a bean that contains a collection of other beans that
    Message 1 of 8 , Mar 1, 2007
      Hi Jaybird Developers


      I'm using Hibernate 3.2 + Jaybird 2.1.1 + Firebird 1.5


      In hibernate I try to save a bean that contains a collection of other
      beans that contains a collection of blobs...

      E.g..

      Foo
      Bar
      Blob
      Blob
      Bar
      Blob
      Blob

      session.save(foo);

      ... but following exception is thrown:

      org.hibernate.exception.GenericJDBCException: could not insert:
      [ch.bw.worknavigator.hibernatetest.FooBlob]
      at
      org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
      at
      org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
      at
      org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
      at
      org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2263)
      at
      org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2656)
      at
      org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:52)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
      at
      org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
      at
      org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
      at
      org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
      at
      org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
      at
      ch.bw.worknavigator.hibernatetest.Test.testFooBlobs(Test.java:56)
      at ch.bw.worknavigator.hibernatetest.Test.main(Test.java:32)
      Caused by: org.firebirdsql.jdbc.FBDriverNotCapableException: Not yet
      implemented.
      at
      org.firebirdsql.jdbc.field.FBBlobField.getCachedObject(FBBlobField.java:178)
      at
      org.firebirdsql.jdbc.AbstractPreparedStatement.addBatch(AbstractPreparedStatement.java:767)
      at
      org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:31)
      at
      org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2243)
      ... 10 more




      I have written a small example(testcase) in jdbc to reproduce the problem
      without hibernate:

      The example inserts two records in a batch update...



      import java.io.ByteArrayInputStream;

      import java.sql.*;

      public class Test {

      public static void main(String[] args) throws Exception {

      // get driver...

      String databaseURL =
      "jdbc:firebirdsql:127.0.0.1:d:/test.fdb?sql_dialect=3";
      String user = "sysdba";
      String password = "masterkey";
      String driverName = "org.firebirdsql.jdbc.FBDriver";

      Driver d = null;
      Connection c = null;
      Statement s = null;
      PreparedStatement ps = null;

      try {
      Class.forName(driverName);
      } catch (java.lang.ClassNotFoundException e) {
      System.out.println("Firebird JCA-JDBC driver not found in
      class path");
      System.out.println(e.getMessage());
      return;
      }

      try {
      d = DriverManager.getDriver(databaseURL);
      System.out.println("Firebird JCA-JDBC driver version " +
      d.getMajorVersion() + "." + d.getMinorVersion() + " registered with driver
      manager.");
      } catch (SQLException e) {
      System.out.println("Unable to find Firebird JCA-JDBC driver
      among the registered drivers.");
      showSQLException(e);
      return;
      }

      // get connection...

      try {
      c = DriverManager.getConnection(databaseURL, user, password);
      System.out.println("Connection established.");
      } catch (SQLException e) {
      e.printStackTrace();
      System.out.println("Unable to establish a connection through
      the driver manager.");
      showSQLException(e);
      return;
      }

      // get driver info...
      try {
      java.sql.DatabaseMetaData dbMetaData = c.getMetaData ();

      // Ok, let's query a driver/database capability
      if (dbMetaData.supportsBatchUpdates())
      System.out.println ("Batch updates are supported.");
      else
      System.out.println ("Batch updates are not supported.");


      }
      catch (java.sql.SQLException e) {
      System.out.println ("Unable to extract database meta data.");
      showSQLException (e);
      }

      // create table...

      c.setAutoCommit(true);

      s = c.createStatement();

      try {
      System.out.println("DROP TABLE BLOBTEST");
      s.executeUpdate("DROP TABLE BLOBTEST");
      } catch (java.sql.SQLException e) {
      }

      System.out.println("CREATE TABLE BLOBTEST(ID NUMERIC(18,0) NOT
      NULL PRIMARY KEY, NAME VARCHAR(10), DATA BLOB SUB_TYPE 0 SEGMENT SIZE
      80)");
      s.executeUpdate("CREATE TABLE BLOBTEST(ID NUMERIC(18,0) NOT NULL
      PRIMARY KEY, NAME VARCHAR(10), DATA BLOB SUB_TYPE 0 SEGMENT SIZE 80)");

      c.setAutoCommit(false);



      // -->>
      // -->>



      // insert two records in a batch update...

      try {

      // record 1...

      byte[] bytes1 = new byte[]{65, 65, 65, 65};

      ByteArrayInputStream bais = new ByteArrayInputStream(bytes1);

      System.out.println("INSERT INTO BLOBTEST ( ID, NAME, DATA )
      VALUES ( ?, ?, ?)");
      ps = c.prepareStatement("INSERT INTO BLOBTEST ( ID, NAME, DATA
      ) VALUES ( ?, ?, ?)");
      ps.setLong(1, 1);
      ps.setString(2, "One");
      ps.setBinaryStream(3, bais, bytes1.length);

      ps.addBatch(); // => throws
      org.firebirdsql.jdbc.FBDriverNotCapableException: Not yet implemented.
      <------------------

      // record 2...

      // byte[] bytes2 = new byte[]{66, 66, 66, 66};
      //
      // bais = new ByteArrayInputStream(bytes2);
      //
      // System.out.println("INSERT INTO BLOBTEST ( ID, NAME, DATA )
      VALUES ( ?, ?, ?)");
      // ps.setLong(1, 2);
      // ps.setString(2, "Two");
      // ps.setBinaryStream(3, bais, bytes2.length);
      // ps.addBatch();

      ps.executeBatch();

      c.commit();



      // <<--
      // <<--


      } catch (Exception ex) {
      ex.printStackTrace();
      try {
      if (c != null)
      c.rollback();
      } catch (SQLException e) {
      showSQLException(e);
      }
      } finally {
      System.out.println("Closing database resources.");
      try {
      if (s != null)
      s.close();
      } catch (SQLException e) {
      showSQLException(e);
      }
      try {
      if (ps != null)
      ps.close();
      } catch (SQLException e) {
      showSQLException(e);
      }
      try {
      if (c != null)
      c.close();
      } catch (SQLException e) {
      showSQLException(e);
      }
      }

      }

      // Display an SQLException which has occured in this application.
      private static void showSQLException(SQLException e) {
      java.sql.SQLException next = e;
      while (next != null) {
      System.out.println(next.getMessage());
      System.out.println("Error Code: " + next.getErrorCode());
      System.out.println("SQL State: " + next.getSQLState());
      next = next.getNextException();
      }
      }
      }



      If I execute it...

      org.firebirdsql.jdbc.FBDriverNotCapableException: Not yet implemented.
      at
      org.firebirdsql.jdbc.field.FBBlobField.getCachedObject(FBBlobField.java:178)
      at
      org.firebirdsql.jdbc.AbstractPreparedStatement.addBatch(AbstractPreparedStatement.java:767)
      at Test.main(Test.java:101)



      Note: If I just insert the id and name (no Blob) it works...



      I read in the Jaybird FAQ that the driver dosn't support Batch Updates.


      Can somebody tell me if you plan to implement or allready working on...

      java.sql.PreparedStatement:

      addBatch(String sql)
      clearBatch()
      executeBatch()

      ...and if so when (in which release) it will be available?



      Thanx
      Michi











      [Non-text portions of this message have been removed]
    • Roman Rokytskyy
      Hi, ... It would also work if you use PreparedStatement.setBytes(...) method. ... Mistake in FAQ. Batch updates are supported for few years already. ... In
      Message 2 of 8 , Mar 2, 2007
        Hi,

        > Note: If I just insert the id and name (no Blob) it works...

        It would also work if you use PreparedStatement.setBytes(...) method.

        > I read in the Jaybird FAQ that the driver dosn't support Batch
        > Updates.

        Mistake in FAQ. Batch updates are supported for few years already.

        > Can somebody tell me if you plan to implement or allready working
        > on...
        >
        > java.sql.PreparedStatement:
        >
        > addBatch(String sql)
        > clearBatch()
        > executeBatch()
        >
        > ...and if so when (in which release) it will be available?

        In general these methods work.

        I did not implement batching of BinaryStream because of unclear
        situation how to handle the stream in that case. The current code for
        the batch updates caches all byte data in memory. To make binary
        stream fit this pattern one would need to fetch the stream into memory
        first, which in general is not acceptable. It is clear that this part
        requires some refactoring.

        In the meantime, please create a small test case for Hibernate and
        send it to me directly (best to roman at rokytskyy.de), I will check
        if there is a workaround that would allow you to solve the issue.

        Roman
      • Francisco - São Paulo - Brazil
        What is the actual version of the JayBird and Firebird? I am using FB 1.5 yet.
        Message 3 of 8 , Mar 5, 2007
          What is the actual version of the JayBird and Firebird?

          I am using FB 1.5 yet.
        • Roman Rokytskyy
          ... FB 2.0.0 (2.0.1 comming soon) and Jaybird 2.1.1. Roman
          Message 4 of 8 , Mar 5, 2007
            > What is the actual version of the JayBird and Firebird?

            FB 2.0.0 (2.0.1 comming soon) and Jaybird 2.1.1.

            Roman
          • Francisco - São Paulo - Brazil
            Is it possible to use Jaybird 2.1.1 with FB 1.5? (otherwise I had to visit all my clients and re-install FB 2.0)
            Message 5 of 8 , Mar 6, 2007
              Is it possible to use Jaybird 2.1.1 with FB 1.5? (otherwise I had to
              visit all my clients and re-install FB 2.0)

              Roman Rokytskyy escreveu:

              > > What is the actual version of the JayBird and Firebird?
              >
              > FB 2.0.0 (2.0.1 comming soon) and Jaybird 2.1.1.
              >
              > Roman
              >
              > __
              >
              >
              >
              >
              >------------------------------------------------------------------------
              >
              >
              >
            • Roman Rokytskyy
              ... Yes. This is specified in release notes. Roman
              Message 6 of 8 , Mar 6, 2007
                > Is it possible to use Jaybird 2.1.1 with FB 1.5? (otherwise I had to
                > visit all my clients and re-install FB 2.0)

                Yes. This is specified in release notes.

                Roman
              • Francisco - São Paulo - Brazil
                Ok, thanks, how about the oposite? Accessing FB 2.0 with this Implementation-Version: 1.5.5JDK_1.4 (build: CVSTag=HEAD date=200412051247) Is that alright or it
                Message 7 of 8 , Mar 6, 2007
                  Ok, thanks, how about the oposite?
                  Accessing FB 2.0 with this
                  Implementation-Version: 1.5.5JDK_1.4 (build: CVSTag=HEAD date=200412051247)

                  Is that alright or it doesnt work too?


                  Roman Rokytskyy escreveu:

                  > > Is it possible to use Jaybird 2.1.1 with FB 1.5? (otherwise I had to
                  > > visit all my clients and re-install FB 2.0)
                  >
                  > Yes. This is specified in release notes.
                  >
                  > Roman
                  >
                  >
                  >
                  >------------------------------------------------------------------------
                  >
                  >No virus found in this incoming message.
                  >Checked by AVG Free Edition.
                  >Version: 7.5.446 / Virus Database: 268.18.7/711 - Release Date: 05/03/2007 09:41
                  >
                  >

                  --
                  /*----------------------------*/
                  When you have a hammer
                  Everything looks like a nail.
                  /*----------------------------*/
                • Roman Rokytskyy
                  ... How about reading release notes? You will find that there s nothing about FB 2.0. ... Most code will work, but some DatabaseMetaData methods will return
                  Message 8 of 8 , Mar 6, 2007
                    > Ok, thanks, how about the oposite?

                    How about reading release notes? You will find that there's nothing about
                    FB 2.0.

                    > Accessing FB 2.0 with this
                    > Implementation-Version: 1.5.5JDK_1.4 (build: CVSTag=HEAD
                    > date=200412051247)
                    >
                    > Is that alright or it doesnt work too?

                    Most code will work, but some DatabaseMetaData methods will return false
                    results or throw exceptions. Also you will get some exceptions in
                    ParameterMetaData. No support for UTF8 charset (UNICODE_FSS is supported).

                    Roman
                  Your message has been successfully submitted and would be delivered to recipients shortly.