-->
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: Problems mapping byte[] to DB2400
PostPosted: Mon Sep 18, 2006 4:39 am 
Newbie

Joined: Mon Sep 18, 2006 4:14 am
Posts: 5
Hibernate version:
V3.1.3

Mapping documents:
Code:
<hibernate-mapping package="xxx.xxx.xxx">
   <class name="Xxxx" table="JAF06I" lazy="true">
      ...
      ...
      <property name="FileData" not-null="false" lazy="true" length="4000000">
         <column name="J6DATA" length="4000000" not-null="false"/>         
      </property>   
      ...
      ...
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Just initializing the factory

Full stack trace of any exception that occurs:
No Trace

Name and version of the database you are using:
DB2/400 V5R3M0

The generated SQL (show_sql=true):
On MySQL:
Code:
create table JAF06I (
   ...
   ...
   J6DATA mediumblob,
   ...
   ...
)

On DB2/400:

Code:
create table JAF06I (
   ...
   ...
   J6DATA varchar(4000000) for bit data,
   ...
   ...
)


Debug level Hibernate log excerpt:
...
Unsuccessful: create table JAF06I
[SQL0604]
...

Ok. So I need to get hibernate mapping working with multiple databases including DB2/400.

For some reason when I do mapping above, it tries to create varchar(4000000) for bit data instead of blob(4000000).

If I force column as blob(4000000) with sqltype attribute, it won't work with MySQL anymore.

Is this bug, feature or am I doing it entirely wrong ?

Here is also bit of the class I try map:
Code:
...
   ...
   private byte[] fileData = null;
   ...
   ...
   ...
   public void setFileData(byte[] fileData) {
      this.fileData = fileData;
   }
   public byte[] getFileData() {
      return fileData;
   }
   ...
   ...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 18, 2006 7:03 am 
Newbie

Joined: Mon Sep 18, 2006 4:14 am
Posts: 5
OK. I just browsed through the DB2400Dialect code and looked into MySQLDialect too. Then I checked out the DB2/400 documentation and came into this decision - it is a BUG.

Correct me if I am wrong.

Here is documentation about DB2/400 datatypes: http://publib.boulder.ibm.com/infocente ... h2data.htm

In DB2Dialect it says:
registerColumnType( Types.VARBINARY, "varchar($l) for bit data" );

I am trying to create field with lenght of 4000000 and in documentation it says that VARCHAR must be between 1 and 32762 inclusive.

In MySQLDialect is say:
registerColumnType( Types.VARBINARY, "longblob" );
registerColumnType( Types.VARBINARY, 16777215, "mediumblob" );
registerColumnType( Types.VARBINARY, 65535, "blob" );
registerColumnType( Types.VARBINARY, 255, "tinyblob" );

I think that in DB2400Dialect is should be something like:
registerColumnType( Types.VARBINARY, "blob($l)" );
registerColumnType( Types.VARBINARY, 32762 "varchar($l) for bit data" );

Am I right ?

(BTW, IMHO that VARCHAR type shouldn't be used to store binary data anyway. In my experience it fails on some database versions and fixlevels, but that is entirely different matter. There is also VARBINARY datatype natively so there is no need to use VARCHAR for bitdata anyway)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 18, 2006 7:27 am 
Newbie

Joined: Mon Sep 18, 2006 4:14 am
Posts: 5
I can go around the problem with this custom dialect class:

public class DB2400CustomDialect extends DB2400Dialect {
public DB2400CustomDialect() {
super();
registerColumnType( Types.VARBINARY, "blob($l)" );
}
}

I don't know was this correct way to fix it, but it works. Maybe dialect should use 'VARBINARY' instead of 'VARCHAR for bit data'. Well I leave it to you.

"For a VARBINARY column, the length attribute must be between 1 through 32740 inclusive. For a BLOB column, the length attribute must be between 1 through 2 147 483 647 bytes inclusive."

Posting ticket to JIRA maybe ?


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.