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 dese开发者_StackOverflowrializing 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.
精彩评论