views:

1342

answers:

2

how to read my blob column from mysql to string type in hibernate

I have try this way but alway return me: [B@196f4b5

     Article article2=f.daoArticle.findById(article.getSrcUrl());

     String vbody = article2.getArticle();
        System.out.println(vbody);
\\hbm
 <class catalog="ariso" name="countaword.ariso.dao.Article" table="article">
  <id name="srcUrl" type="java.lang.String">
   <column length="200" name="SrcUrl"/>
   <generator class="assigned"/>
  </id>
  <property column="Article" generated="never" lazy="false"
   name="article" type="text" not-null="true" length="10485760"/>
 </class>

\\

any helps? It took me 3 hours!!!

+1  A: 

I suggest you check the following page from the interwebtubes:

https://www.hibernate.org/76.html

It describes how to create a custom hibernate UserType to map a CLOB/BLOB to a string.

Martlark
Broken link, sad face :(
Matt Ball
A: 

You could use this class from the spring-orm library. Be aware, though, that Springs (B|C)LOB handling relies on a lot of framework classes that need to be initialized correctly. I think you should either switch to using spring for handling hibernate completely or just use the class' source as inspiration.

Maarten Winkels