2012-11-08 22 views
1

我正在使用Hibernate 3.6.10版本并在保存记录(学生)后尝试读取Clob数据类型。它抛出错误“无法重置读者”使用getCharacterStream API读取Clob对象导致“java.sql.SQLException:无法重置读取器”

public class Student implements java.io.Serializable { 

    private long studentId; 
    private String studentName; 
    private Address studentAddress; 
    private Clob searchProfileText; 

测试时......第一我节省了学生的记录,然后尝试再次得到该记录的searchProfileText作为followiing

1  student1.setSearchProfileText(clob); 
2  session.save(student1); 
3  System.out.println("Reading Clob : " + student1.getSearchProfileText().getCharacterStream()); 

行号3,我得到以下异常

java.sql.SQLException: could not reset reader 
at org.hibernate.engine.jdbc.ClobProxy.resetIfNeeded(ClobProxy.java:178) 

我试图session.flush();,然后用下面的代码重新加载数据,还是同样的错误:

session.flush(); 
session.get(Student.class, student1.getStudentId()); 
System.out.println("Reading Clob : " + student1.getSearchProfileText().getCharacterStream()); 

观察2:

即使我获得一个包含使用休眠标准CLOB数据的记录,并把限制针对CLOB列,我不能读取记录之后访问CLOB数据。我认为,这是3.6.10最终的BUG!

请帮助摆脱这种错误的。我曾尝试在这所有相关主题,但没有成功,但:(

回答

0

因为你是从same object instance阅读getSearchProfileText对象,它不能这样做,因为我想你需要在读取它之前重新加载对象,例如

Serializable id = session.save(student1); 
    //commit the transaction 
    Student student = session.get(Student.class, id); 
    System.out.println("Reading Clob :: " 
          + student.getSearchProfileText().getCharacterStream()); 
+1

是的,你是正确的。但是,我不能使用flush()来同步新的学生记录然后重新载入相同的记录以再次读取Clob对象:(你能帮忙吗?如何在保存之后读取相同的Clob对象提交会话之前的休眠会话。记住它适用于Hibenrate 3.2.5,但不适用于Hibernate 3.6.10。 – Dhrubo

+0

@DhruboBhattacharjee:你是如何创建CLOB的?难道你不能使用相同的源来引用它需要的地方吗? –

+0

使用session.getLobHelper()。createClob(String)创建CLOB ...并且甚至在保存记录后我都无法访问相同的clob对象。指针没有得到休息的第一个位置。我目前正在使用getSubString()API。让我知道是否有任何方法使用getCharecterStream()API。 – Dhrubo