Software Development

Clob Processing in Java, Spring, and Hibernate

Tagged with: , ,

The following sections show how to save CLOB to a Relational Database using Java, Spring, and Hibernate. This example is helpful for Java developers to implement using two classes from Spring Framework:

  1. OracleLobHandler
  2. NativeJdbcExtractor (This example has been tested in Weblogic J2ee Container, and this example uses WebLogicNativeJdbcExtractor.)

Spring Framework applicationContext.xml configuration:

<bean id=”mySessionFactory class=”org.springframework.orm.hibernate3.LocalSessionFactoryBean”>

<property name=”dataSource” ref=”myDataSource” />

<property name=”lobHandler” ref=”lobHandler” />

<property name=”mappingResources”>

<list> <value>com/clob/hibernate/lohHandler.hbm.xml</value>

</list></property> <property name=”hibernateProperties”><props><prop key=”hibernate.dialect”>org.hibernate.dialect.OracleDialect </prop>

<prop key=”hibernate.show_sql”>true</prop>

<prop key=”hibernate.connection.autocommit”>false</prop>

<prop key=”hibernate.connection.release_mode”>auto </prop>

<prop key=”hibernate.jdbc.use_streams_for_binary”>true </prop>

<prop key=”SetBigStringTryClob”>true</prop>




<bean id=”lobHandler” class=””


<property name=”nativeJdbcExtractor”>

<beanclass=”” />



Code block from lobHandler.hbm.xml:

<property name=”extdXml” type=”java.sql.Clob”>

<column name=”DTL_XML” /> </property>

Java bean class:

public class lohHandler implements {

 private Clob extdXml;

public void setExtdXml(Clob extdXml) { this.extdXml = extdXml;} public Clob getExtdXml() { return this.extdXml;}

public void setClobContent( String sourceStream )throws IOException{

setExtdXml( Hibernate.createClob( sourceStream ) );

}} Spring Framework Controller class:Upload the xml file and store contents of xml file in a String.Instantiate the bean.

lohHandler lHandler = new lohHandler ();


setClobContent() method inturn calls Hibernate.createClob() method, which creates a CLOB out of a String. Now we are ready to save the lHandler bean object in a Hibernate Session.

To learn more technical tips and tricks from our experts, contact Unidev.