-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Could not insert into Oracle Database
PostPosted: Fri Feb 11, 2005 9:32 am 
Newbie

Joined: Mon Oct 18, 2004 12:29 pm
Posts: 8
Hi everyone...
I have a very weird problem when trying to insert data into an Oracle DataBase (ver. 10.1.0.2.0). The system was fine when using MySql, but I get an error now that I switched to Oracle. I don't think is a Hibernate issue with oracle, but maybe someone out there can give me a hand.

I'm using Hibernate 2.1.4.

I have simplified the code, and is as follows:

Code:
MDataSet dataSet = new MDataSet();

DataSetModel dataModel = new DataSetModel();
readRawData(dataModel, "C:\\Documents and Settings\\alejandro\\Mis documentos\\test2.txt");

// Iterate DataSeriesVector and create data columns
Iterator itt = dataModel.getDataColumnModelVector().iterator();

for (int i = 0; itt.hasNext(); i++) {
   DataColumnModel dataSeries = (DataColumnModel) itt.next();

   // Create the column

   MDataColumn mDataColumn = dataSeries.getDataColumn();


   // Add it to the set
   dataSet.getDataColumns().add(mDataColumn);
   mDataColumn.setDataSetRef(dataSet);
}

session.saveOrUpdate(dataSet);


Here is readRawData():

Code:
private static void readRawData(DataSetModel model, String file) throws FileNotFoundException, IOException {
   int timeIndex = -1;

   // Read headers
   BufferedReader reader = new BufferedReader(new FileReader(file));
   String line = reader.readLine();

   Pattern pattern = Pattern.compile("\\t");
   String[] heads = pattern.split(line);

   Vector[] headsData = new Vector[heads.length];

   for (int i = 0; i < heads.length; i++) {
      if (heads[i].equals("Time")) {
         timeIndex = i;
      }

      headsData[i] = new Vector();

      MDataColumn mDataColumn = new MDataColumn();
      mDataColumn.setName(heads[i]);
      mDataColumn.setType(i < 3 ? MDataColumn.TYPE_STRING : MDataColumn.TYPE_FLOAT);

      model.addDataColumnModel(new DataColumnModel(mDataColumn, null));
   }

   // Read data
   line = reader.readLine();

   int lc = 0;

   while (line != null) {
      line = line.replace(',', '.');

      lc++;

      if (line.trim().length() == 0) {
         continue;
      }

      String[] items = pattern.split(line);

      float xValue = 0;
      float yValue = 0;

      try {
         xValue = Float.parseFloat(items[timeIndex]);
      } catch (NumberFormatException e) {
         continue;
      }

      for (int i = 0; i < heads.length; i++) {
         DataColumnModel ds = (DataColumnModel) model.getDataColumnModelVector().get(i);

         if (i < 3) {
            headsData[i].add(items[i]);
            continue;
         }

         if (i >= items.length) {
            headsData[i].add(new Float(Float.NaN));
            continue;
         }

         try {
            headsData[i].add(new Float(items[i]));   
         } catch (NumberFormatException e) {
            headsData[i].add(new Float(Float.NaN));
         }
      }

      line = reader.readLine();
   }

   for (int i = 0; i < headsData.length; i++) {
      String[] strData = null;
      float[] fltData = null;

      if (i < 3) {
         strData = new String[headsData[i].size()];
      } else {
         fltData = new float[headsData[i].size()];
      }

      for (int j = 0; j < headsData[i].size(); j++) {
         if (i < 3) {
            strData[j] = (String) headsData[i].get(j);
         } else {
            fltData[j] = ((Float) headsData[i].get(j)).floatValue();
         }
      }

      DataColumnModel dataColumnModel = (DataColumnModel) model.getDataColumnModelVector().get(i);

      if (i < 3) {
         dataColumnModel.getDataColumn().setStringData(strData);
         dataColumnModel.getDataColumn().setType(MDataColumn.TYPE_STRING);
      } else {
         dataColumnModel.getDataColumn().setFloatData(fltData);
         dataColumnModel.getDataColumn().setType(MDataColumn.TYPE_FLOAT);
      }
   }



Here comes the weird part... I know for a fact that is not hibernate, and this is why; look at the try/catch in readRawData
Code:
try {
        headsData[i].add(new Float(items[i]));   
} catch (NumberFormatException e) {
   headsData[i].add(new Float(Float.NaN));
}


If I replace
Code:
headsData[i].add(new Float(items[i]));   


With
Code:
//Or any float, including NaN, Positive Infinity and Negative Infinity
headsData[i].add(new Float(0));   


The code works... and loosing my head here. Any help is appreciate it.
Thanks for the help.


Top
 Profile  
 
 Post subject: Found something
PostPosted: Fri Feb 11, 2005 11:02 am 
Newbie

Joined: Mon Oct 18, 2004 12:29 pm
Posts: 8
I found something very peculiar.
Here is the mapping of one of the objects.

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
   <class name="de.amarant.ag.model.master.MDataColumn" table="QASG_DATA_COLUMN">

      <id name="id" type="int" unsaved-value="0">
         <generator class="increment"/>
      </id>

      <property name="name"/>
      <property name="type"/>

      <property name="data">   
         <column name="data" sql-type="LONG RAW"/>
      </property>

      <many-to-one name="dataSetRef" column="data_set_id" not-null="true"/>

   </class>
</hibernate-mapping>


The property "data" is a blob created using Hibernate.createBlob() method. I located the real problem when trying to insert. Here is the method of MDataColumn that creates the blob

Code:
      public void writeData() throws Exception {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      GZIPOutputStream gzipOS = new GZIPOutputStream(baos);
      
      if (type == TYPE_FLOAT) {
         writeFloatData(gzipOS);
      } else {
         writeStringData(gzipOS);
      }
      
//      if (type == TYPE_FLOAT) {
//         writeFloatData(baos);
//      } else {
//         writeStringData(baos);
//      }
      
      data = Hibernate.createBlob(baos.toByteArray());      
   }


If I try to use the GZIPOutputStream then the program cannot insert the data on the database, otherwise everything works fine. I know that the GZIPOutputStream is working correctly 'cause I tried earlier with MySql and everything worked correctly. The error I get when using Oracle and the GZIPOutputStream is:

Code:
WARN  - SQL Error: 3106, SQLState: 63000
ERROR - ORA-03106: fatal two-task communication protocol error

WARN  - SQL Error: 3106, SQLState: 63000
ERROR - ORA-03106: fatal two-task communication protocol error

WARN  - SQL Error: 3106, SQLState: 63000
ERROR - ORA-03106: fatal two-task communication protocol error

WARN  - SQL Error: 3106, SQLState: 63000
ERROR - ORA-03106: fatal two-task communication protocol error

ERROR - could not insert: [de.amarant.ag.model.master.MDataColumn#15]
java.sql.BatchUpdateException: ORA-03106: fatal two-task communication protocol error

   at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
   at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8739)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatchingBatcher.addToBatch(BatchingBatcher.java:34)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at de.amarant.ag.test.OracleError.main(OracleError.java:137)
Exception in thread "main" net.sf.hibernate.JDBCException: could not insert: [de.amarant.ag.model.master.MDataColumn#15]
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:478)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at de.amarant.ag.test.OracleError.main(OracleError.java:137)
Caused by: java.sql.BatchUpdateException: ORA-03106: fatal two-task communication protocol error

   at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
   at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8739)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatchingBatcher.addToBatch(BatchingBatcher.java:34)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
   ... 7 more
ERROR - Could not synchronize database state with session
net.sf.hibernate.JDBCException: could not insert: [de.amarant.ag.model.master.MDataColumn#15]
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:478)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at de.amarant.ag.test.OracleError.main(OracleError.java:137)
Caused by: java.sql.BatchUpdateException: ORA-03106: fatal two-task communication protocol error

   at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
   at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8739)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatchingBatcher.addToBatch(BatchingBatcher.java:34)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
   ... 7 more


The sql created by Hibernate:
Hibernate: insert into QASG_DATA_SET (name, id) values (?, ?)
Hibernate: insert into QASG_DATA_COLUMN (name, type, data, data_set_id, id) values (?, ?, ?, ?, ?)

Thanx again in advanced


Top
 Profile  
 
 Post subject: Re: Could not insert into Oracle Database
PostPosted: Mon Feb 20, 2012 1:57 pm 
Newbie

Joined: Mon Feb 20, 2012 1:53 pm
Posts: 2
I realize that the original post is a bit old, but I'm actually encountering the same problem with the same version of Oracle, but with Hibernate 3.6. We're creating our blobs in an entirely different manner, however. If I ever find a solution, I'll post it here for posterity.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.