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