-->
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.  [ 2 posts ] 
Author Message
 Post subject: CLOB truncation on DB2 when using 2 or 3 byte chars (UTF8)
PostPosted: Tue Jan 30, 2007 7:16 am 
Newbie

Joined: Tue Jan 30, 2007 5:02 am
Posts: 2
Location: The Netherlands
I am using a CLOB column in DB2 mapped to a String in Java with the Hibernate "Text" mapping. The column in DB2 has a CCSID 1208 which means "UTF8" (= Unicode)

The truncation occurs when characters are used that are UTF8 coded in more than one byte. Then the string is truncated when persisted in the database.

For this example I use the string
"Granpré Molière†; 0123456789". This string has two diacritical marks in it. The è is coded in two bytes in UTF8 and the † in three bytes.
This string will be stored as "Granpré Molière†; 012345".
So "6789" is not stored.

It appears as though Hibernate does not take into account that a character can be more than 1 byte.

This is (more or less) DB2 specific because on Oracle9 the same string is stored and retrieved correctly as CLOB in a UTF8 database.
On Oracle I used the same table definition and a different ...hibernate.cfg.xml. Everything else the same.

Finally I tried a bypass of JBoss and Hibernate and stored the same String directly via Jdbc into the DB2 table and retrieved it.
This works 100% OK!.
So this clearly points to a problem somewhere in Hibernate.


Hibernate version:
Hibernate 3.2.0.ga

Mapping documents:
<class
name="com.getronics.slg.civmk.common.model.TestTabel"
table="TSTM00" lazy="true"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="TSTM00"
</meta>

<id
name="key"
type="java.lang.Long"
column="TSTKEY"
>
<meta attribute="field-description">
@hibernate.id
generator-class="sequence"
type="java.lang.Long"
column="TSTKEY"

@hibernate.generator-param
name="sequence"
value="TSTQ00"

</meta>
<generator class="sequence">
<param name="sequence">TSTQ00</param>
</generator>

</id>

<property
name="xmlData"
type="text"
column="TSTDATA"
not-null="false"
>
<meta attribute="field-description">
@hibernate.property
column="TSTDATA"
not-null="false"
</meta>
</property>
<!-- associations -->

</class>



Code between sessionFactory.openSession() and session.close():
Code:
           tx = sess.beginTransaction();
           // actuele persoontabellen
           List tstRecords = sess.createQuery(
                   "from TestTabel tst where " +
                   "tst.key=1580").list();
           Iterator recordIt = tstRecords.iterator();
           TestTabel tst =
              (TestTabel)recordIt.next();
           System.out.println("XML: "+tst.getXmlData());
          
          
           tst.setXmlData("Granpré Molière†; 0123456789");
           sess.flush();
           tx.commit();//


Full stack trace of any exception that occurs: No exception

Name and version of the database you are using:
DB2 UDB for ISeries V5R3


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 31, 2007 6:09 am 
Newbie

Joined: Tue Jan 30, 2007 5:02 am
Posts: 2
Location: The Netherlands
Correction:
The mentioned test String has three diacritical marks in it.


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