2012-11-08 19 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