I've got a ClobType that extends Hibernate's UserType and does about what you'd expect: converts the clob found in the database to a String. I mapped my clob columns to the ClobType, and those columns render nicely when I access them in my JSP pages.
But now that I'm trying to set the value, I'm stumped. Because I can write ${myObject.longField}
in my JSP pages tells me I can probably say
String s = myObject.getLongField().toString();
and get the string, despite the fact that LongField is of type ClobType.
What I don't know is how to use the setter. I can instantiate a ClobType easily, but how do I give it string data that it needs to persist as a blob?
ClobType clobType = new ClobType();
String s = "... a really REALLY long string ...";
/* a miracle occurs */
myObject.setLongField( clobType );
myObjectDAO.saveOrUpdate( myObject );
What is the miracle I need in order to give the ClobType a string value?
Or, is there a better (or more proper) way of having my two setters return Strings rather than ClobTypes? Is there a special mapping that does this? My business logic has no need to know that a given column is implemented as a blob.
I think if you're using a reasonably current hibernate, you can map a java String to a database CLOB without using a custom UserType
at all.
Try
@Lob
public String getLongField() { return longField; }
with longField just a String
.
If this works, it'll be much simpler than what you're doing.