Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help on reading CLOB column

 
Ghulam Rashid
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate Code - Reading CLOB Data
----------------------------------------------------------------------------------------------------------------------------------
mapping.xml
-------------
<property name="clobData" type="clob">
<column name="ClobData" />
</property>

java code
---------
String clobHQL = "from ClobTest";
Query query = session.createQuery(clobHQL);

List result = query.list();

ClobPOJO clobPOJO = (ClobPOJO)result.get(0);
java.sql.Clob dataAsClob = clobPOJO.getClobData();

// FIRST WAY - Error
String dataAsString=dataAsClob.getSubString(1, (int) dataAsClob.length());

// SECOND WAY - Error
Reader reader=dataAsClob.getCharacterStream();
CharArrayWriter writer=new CharArrayWriter();
int i=-1;

while ( (i=reader.read())!=-1)
{
writer.write(i);
}

String dataAsString = new String(writer.toCharArray());


Error
========
java.io.IOException: [PWS0001] Function did not complete successfully.
at com.ibm.as400.access.AS400JDBCInputStream.read(AS400JDBCInputStream.java:305)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:200)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:239)
at java.io.BufferedInputStream.read(BufferedInputStream.java:294)
at com.ibm.as400.access.ConvTableReader.fillCache(ConvTableReader.java:180)
at com.ibm.as400.access.ConvTableReader.read(ConvTableReader.java:500)
 
Ghulam Rashid
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correction to HQL
String clobHQL = "from ClobPOJO";
 
Ghulam Rashid
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am able to get the data from CLOB. I had to made changes in the mapping and pojo to change the data type.
I changed the clob type to text (hibernate type) which is java equivalent "Very Long Strings"/java.lang.String.

mapping.xml
-------------
<property name="clobData" type="text/string">
<column name="ClobData" />
</property>

But, I am still unable to figure out why clob hibernate type is not supported. There is ClobImpl class and org.hibernate.type.ClobType
in hibernate but do not have enough time to run into hibernate jungle.

I hope i wont lose data using text/string.

Thanks
 
Halcon Guatemala
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ghulam, sorry if You explained it before...
What type is your clobData attribute of in your plain class?
I'm getting similar troubles with LONG type of Oracle.
Thanks
 
Ghulam Rashid
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In plain class (POJO) the data type is java.lang.String. And, in mapping it is text. But, this is for CLOB column.

Probably, for your LONG type you can map with big_decimal in mapping and in pojo you can use java.math.BigDeciml. Probably that may help.

Thanks
Rashid
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic