简体   繁体   中英

Java: merge instance w/ Oracle CLOB data using Hibernate

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!)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM