Java:使用 Hibernate 合并实例与 Oracle CLOB 数据

发布于 2024-10-20 20:48:44 字数 1059 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜空下最亮的亮点 2024-10-27 20:48:44

解决了!

需要在列上指定一个注释@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文