title: Hibernate: How to set the value of a custom UserType
body: <p>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.</p>
  
  <p>But now that I'm trying to set the value, I'm stumped.  Because I can write <code>${myObject.longField}</code> in my JSP pages tells me I can probably say </p>
  
  <pre><code>String s = myObject.getLongField().toString();
  </code></pre>
  
  <p>and get the string, despite the fact that LongField is of type ClobType.</p>
  
  <p>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?</p>
  
  <pre><code>ClobType clobType = new ClobType();
  String s = "... a really REALLY long string ...";
  /* a miracle occurs */
  myObject.setLongField( clobType );
  myObjectDAO.saveOrUpdate( myObject );
  </code></pre>
  
  <p>What is the miracle I need in order to give the ClobType a string value?</p>
  
  <p>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.   </p>