-->
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.  [ 6 posts ] 
Author Message
 Post subject: Serializable type and Derby
PostPosted: Thu Jan 04, 2007 10:53 am 
Newbie

Joined: Thu Jan 04, 2007 10:17 am
Posts: 1
Hi,

I'm doing some sort of experiment with Hibernate, and I've found a problem I can't solve.
The class I'm trying to persist has a java.lang.Serializable attribute, and I've mapped it to a property of type serializable.
The test application stores some BigInteger and String values succesfully. The problem arises when storing a little bean class with 4 attributes using Apache Derby 10.2.2.0:

Code:
13:21:45,783  WARN JDBCExceptionReporter:77 - SQL Error: -1, SQLState: 22001
13:21:45,783 ERROR JDBCExceptionReporter:78 - A truncation error was encountered trying to shrink VARCHAR () FOR BIT DATA 'XX-RESOLVE-XX' to length 255.
13:21:45,798 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.DataException: could not insert: [com.gridsystems.checkpointing.CheckPoint]
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2217)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2610)
   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 org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at ...

Caused by: java.sql.SQLException: A truncation error was encountered trying to shrink VARCHAR () FOR BIT DATA 'XX-RESOLVE-XX' to length 255.
   at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
   at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
   at org.apache.derby.client.am.PreparedStatement.executeUpdate(Unknown Source)
   at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2197)
   ... 12 more
Caused by: org.apache.derby.client.am.SqlException: A truncation error was encountered trying to shrink VARCHAR () FOR BIT DATA 'XX-RESOLVE-XX' to length 255.
   at org.apache.derby.client.am.Statement.completeExecute(Unknown Source)
   at org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(Unknown Source)
   at org.apache.derby.client.net.NetStatementReply.readExecute(Unknown Source)
   at org.apache.derby.client.net.StatementReply.readExecute(Unknown Source)
   at org.apache.derby.client.net.NetPreparedStatement.readExecute_(Unknown Source)
   at org.apache.derby.client.am.PreparedStatement.readExecute(Unknown Source)
   at org.apache.derby.client.am.PreparedStatement.flowExecute(Unknown Source)
   at org.apache.derby.client.am.PreparedStatement.executeUpdateX(Unknown Source)
   ... 15 more




Hibernate version:
3.2.1

Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
  <class name="xxx.yyy.zzz.CheckPoint" table="CHECKPOINTS">
    <composite-id name="id" class="xxx.yyy.zzz.CheckPointID">
      <key-property name="taskName"></key-property>
      <key-property name="microtaskID"></key-property>
    </composite-id>
   
    <property name="data" type="serializable"></property>

  </class>
</hibernate-mapping>


Name and version of the database you are using:
Apache Derby 10.2.2.0

The generated SQL (show_sql=true):

Code:
Hibernate: insert into CHECKPOINTS (data, taskName, microtaskID) values (?, ?, ?)
13:21:45,689 DEBUG SerializableType:80 - binding '2c6d8085f3f280a6e3efedaee7f2e9e4f3f9f3f4e5edf3aee3e8e5e3ebf0efe9eef4e9eee7aed4e5f3f4c2e5e1eec9602e462c3b2098828084da808ce2efefece5e1eec6e9e5ece4c98088e9eef4c6e9e5ece4db8090f3f4f2e9eee7c1f2f2e1f9c6e9e5ece4f48093dbcceae1f6e1afece1eee7afd3f4f2e9eee7bbcc808bf3f4f2e9eee7c6e9e5ece4f48092cceae1f6e1afece1eee7afd3f4f2e9eee7bbf8f081808080e3f5f28093dbcceae1f6e1aeece1eee7aed3f4f2e9eee7bb2d52d667699dfbc7828080f8f080808082f4809cedf9a0e6e9f2f3f4a0f3f4f2e9eee7a0e9eea0f4e8e5a0e1f2f2e1f9f4809dedf9a0f3e5e3efeee4a0f3f4f2e9eee7a0e9eea0f4e8e5a0e1f2f2e1f9f48089edf9a0d3f4f2e9eee7' to parameter: 1
13:21:45,704 DEBUG StringType:80 - binding 'a' to parameter: 2
13:21:45,704 DEBUG StringType:80 - binding 'b' to parameter: 3



The same code works perfectly when using HSQLDB 1.8.0.
Am I doing something wrong?

Any help will be appreciated.


Top
 Profile  
 
 Post subject: Re: Serializable type and Derby
PostPosted: Fri Apr 01, 2011 3:56 am 
Newbie

Joined: Sat Dec 03, 2005 5:35 am
Posts: 11
Hi,

This post is a bit old, but I had the same problem and seen no solution over the net.

Context :
We used HSQLDB for unitary testing as a in-memory database but HSQLDB 1.8 is not handling lock/select for update.
Since a few version, Derby had a also a full in-memory database and manage the lock, great, let's use it !

Problem :
See previous post : Hibernate mapping "serializable" is mapped to VARCHAR(255) for BIT DATA in derby and it was working with HSQLDB 1.8.

Solution :
After a few hours of code exploration and googling, here is my solution :
  1. Create your own DerbyDialect extended standard one
  2. In this dialect, when hibernate ask for typename, test if it is serializable and replace "VARCHAR(255) for BIT DATA" by "LONG VARCHAR FOR BIT DATA"
[*] Configure Hibernate to use your own dialect

Code:
package mytestpackage;

public class DerbyDialect extends org.hibernate.dialect.DerbyDialect {

   public DerbyDialect() {
      super();
   }

   @Override
   public String getTypeName(final int code, final int length, final int precision, final int scale) throws HibernateException {

      String typeName = super.getTypeName(code, length, precision, scale);

      // test if it is serialiable type (-3)
      if (code == -3) {
         typeName = "LONG VARCHAR FOR BIT DATA";
      }

      return typeName;
   }
}


Top
 Profile  
 
 Post subject: Re: Serializable type and Derby
PostPosted: Thu Apr 14, 2011 8:03 am 
Newbie

Joined: Sat Dec 03, 2005 5:35 am
Posts: 11
Cleaner solution and use of BLOB instead. Be careful, BLOB can not be null.

Code:
   
public DerbyDialect() {
      super();
      registerColumnType(Types.LONGVARBINARY, "blob");
      registerColumnType(Types.VARBINARY, "blob");

   }


Top
 Profile  
 
 Post subject: Re: Serializable type and Derby
PostPosted: Tue Apr 24, 2012 4:57 pm 
Newbie

Joined: Tue Apr 10, 2012 2:57 pm
Posts: 8
Hi...This post is quite old so I think people have solved the issue.

I just came across the same problem, except I am having the issue with VARCHAR where my column is truncated to 255 and therefore, failing.

I believe I can persist the objects, but cannot retrieve it using query. Does anyone know how to fix it?


Top
 Profile  
 
 Post subject: Re: Serializable type and Derby
PostPosted: Fri May 25, 2012 4:25 pm 
Newbie

Joined: Tue Oct 14, 2008 3:08 pm
Posts: 8
Location: Brasil
I got the following error:

Code:
Caused by: java.sql.SQLDataException: A truncation error was encountered trying to shrink VARCHAR () FOR BIT DATA '(Binary data value not displayed)' to length 255.
   at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
   at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
   at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
   at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
   at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source)
   at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown Source)
   at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
   at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:56)
   ... 57 more
Caused by: java.sql.SQLException: A truncation error was encountered trying to shrink VARCHAR () FOR BIT DATA '(Binary data value not displayed)' to length 255.
   at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
   at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
   ... 68 more
Caused by: ERROR 22001: A truncation error was encountered trying to shrink VARCHAR () FOR BIT DATA '(Binary data value not displayed)' to length 255.
   at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
   at org.apache.derby.iapi.types.SQLBinary.checkHostVariable(Unknown Source)
   at org.apache.derby.exe.acd381409ax0137x85a8xa462x000000d63cb016.e0(Unknown Source)
   at org.apache.derby.impl.services.reflect.DirectCall.invoke(Unknown Source)
   at org.apache.derby.impl.sql.execute.RowResultSet.getNextRowCore(Unknown Source)
   at org.apache.derby.impl.sql.execute.NormalizeResultSet.getNextRowCore(Unknown Source)
   at org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(Unknown Source)
   at org.apache.derby.impl.sql.execute.InsertResultSet.open(Unknown Source)
   at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
   ... 62 more


I was getting this error for a very silly reason: I forgot to put @ManyToOne and a @Embedded in two properties of my persistent object. I actually didn't have a Serializable mapping..

_________________
Bruno Medeiros


Top
 Profile  
 
 Post subject: Re: Serializable type and Derby
PostPosted: Sat Jun 02, 2012 2:05 pm 
Newbie

Joined: Tue Apr 10, 2012 2:57 pm
Posts: 8
Hello,

I had the similar issue, but a colleague of mine has solved it. Basically it is nothing to do with Hibernate, it is DERBY. Derby's persistent column length is limited to 255. You can't change it permanently without fiddling with DERBY. You can write them back and they will solve it for you..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.