gpt4 book ai didi

java - 使用 getCharacterStream API 读取 Clob 对象导致 "java.sql.SQLException: could not reset reader"

转载 作者:行者123 更新时间:2023-11-29 09:09:08 25 4
gpt4 key购买 nike

我正在使用 Hibernate 3.6.10 版本并在保存记录(学生)后尝试读取 Clob 数据类型。抛出错误“无法重置阅读器”

 public class Student implements java.io.Serializable {

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

在测试时...首先我保存了一条学生记录,然后尝试再次从该记录中获取 searchProfileText,如下所示

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:

即使我使用 Hibernate 条件获取包含 CLOB 数据的记录并对 CLOB 列施加限制,我也无法在获取记录后访问 CLOB 数据。我认为,这是 3.6.10 Final 中的一个 BUG!!!

请帮助消除这个错误。我已经尝试了所有与此相关的主题,但还没有成功:(

最佳答案

由于您正在从 同一对象实例 读取 getSearchProfileText 对象,因此无法这样做,因为指针在设置值后位于末尾。我认为您需要在阅读之前重新加载对象,例如

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

关于java - 使用 getCharacterStream API 读取 Clob 对象导致 "java.sql.SQLException: could not reset reader",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13294373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com