Java:使用 Hibernate 合并实例与 Oracle CLOB 数据
JDK 1.6x、Hibernate 3.2.7、Oracle 10g (ojdbc14.jar)
我有一个包含 clob 的(实体)类。通过 RESTful 调用,我传递了一个字符串,该字符串将成为 clob 的内容。我在将字符串填充到 clob 中以供以后持久化时遇到问题。这是类...
public class MyClass implements java.io.Serializable {
private static final long serialVersionUID = 5507279748316866736L;
private long id;
private String name;
private String description;
private java.sql.Clob featuresJson;
...etc...
这是反序列化代码...
try {
String jsonStr = msoNode.path("features_json").getTextValue();
SerialClob clob = new SerialClob(jsonStr.toCharArray());
mso.setFeaturesJson(clob);
} catch (Exception e) {
log.error("MyClassDeserializer.deserialize(): Exception deserializing the features JSON." + e.getMessage());
}
反序列化后,我进入 Dao 的合并语句...
MyClass savedOverlay = myClassDao.merge(overlay);
其中“overlay”是反序列化的“MyClass”实例。此时我可以查看 clob 内部并查看数据 - 但是返回的实例将 clob 字段清空,并且数据库中的 clob 列也为空!
我的反序列化代码有什么问题?我尝试过其他一些事情,但每次都会失败(至少这是一致的!)
JDK 1.6x, Hibernate 3.2.7, Oracle 10g (ojdbc14.jar)
i have a (entity) class that contains a clob. Through a RESTful call i am passed a string that will be the content of the clob. i am having trouble stuffing the string into a clob for later persistence. here's the class....
public class MyClass implements java.io.Serializable {
private static final long serialVersionUID = 5507279748316866736L;
private long id;
private String name;
private String description;
private java.sql.Clob featuresJson;
...etc...
here's the deserialization code...
try {
String jsonStr = msoNode.path("features_json").getTextValue();
SerialClob clob = new SerialClob(jsonStr.toCharArray());
mso.setFeaturesJson(clob);
} catch (Exception e) {
log.error("MyClassDeserializer.deserialize(): Exception deserializing the features JSON." + e.getMessage());
}
after deserialization, i'm onto the Dao's merge statement...
MyClass savedOverlay = myClassDao.merge(overlay);
where "overlay" is a deserialized "MyClass" instance. at this point i can peek inside the clob and see the data -- however the returned instance has the clob field null'ed out, and the clob column in the database is null as well!
What's wrong with my deserialization code? i've tried a few other things, but get failures each and every time (at least that is consistent!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了!
需要在列上指定一个注释@Lob。已被逆向工程为 java.sql.Clob 类型的同一列也需要更改为 String。
SOLVED!
there is an annotation @Lob that needed to be specified on the column. also the same column that had been reverse-engineered to be of type java.sql.Clob needed to be changed to String.