I am trying to figure out how to use the sample code to get a character stream to write to a Clob field via Hibernate. I have looked at the sample code given on this site.
http://www.hibernate.org/Documentation/UsingClobsWithOracleAndHibernate12
...but I get a ClassCastException when it tries to cast a java.sql.Clob to a oracle.sql.CLOB. What am I doing wrong?
Here is a snippet from my code...
Code:
submData.setData(Hibernate.createClob(" "));
try {
session.refresh(submData, LockMode.UPGRADE); //grabs an Oracle CLOB
oracle.sql.CLOB clob = (oracle.sql.CLOB) submData.getData();
return clob.getCharacterOutputStream();
}
catch (HibernateException ex) {
throw new DataAccessException(ex);
}
catch (SQLException ex) {
throw new DataAccessException(ex);
}
submData is a class that contains a java.sql.Clob field. getData/setData() are the get/setters for subm's Clob field. They return a java.sql.Clob field. The data field is mapped in a Hibernate mapping field like this...
Code:
<property name="data" type="clob" column="DATA"/>
The ClassCastExceptin occurs on the line that gets submData's Data field (java.sql.Clob) and attempts to cast it to a oracle.sql.CLOB.
How do I get around that ClassCastException? I assume I am doing something wrong. Is there another way to get a Writer to the clob field?
-Greg