Announcement Announcement Module
No announcement yet.
Working with Clobs Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Working with Clobs

    Roo 1.1.1.RELEASE (included with STS 2.5.2.RELEASE)
    Oracle 10g
    ojdbc14.jar (
    Hibernate 3.6.0.Final

    I'm having trouble saving Clobs to an Oracle database. I used DBRE and this is what it generated:

    @Column(name = "NOTES", columnDefinition = "CLOB")
    private Clob notes;
    Side note: I initially got a "can not convert clob to string" message when displaying the field, but I solved this by adding a Clob -> String converter to ApplicationConversionServiceFactoryBean.

    When trying to create/update the record, the following error is displayed on the form next to the notes field:

    Failed to convert property value of type java.lang.String to required type java.sql.Clob for property notes; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.sql.Clob] for property notes: no matching editors or conversion strategy found
    There is no message in the console.

    So I created a converter in ApplicationConversionServiceFactoryBean:

    Converter<String, Clob> getStringToClobConverter() {
    	return new Converter<String, Clob>() {
    		public Clob convert(String source) {
    			// Now what?
    Returning null from there gets rid of the error message, but of course the notes data is not saved.

    I'm not sure what to do at this point. It seems like this conversion should be "magically" handled internally, so I feel like I'm going down the wrong path trying to do this conversion myself. Any suggestions?


    - Luke

  • #2
    I am facing the same Problem here ... :/


    • #3

      Take a look to my article at It uses a pretty close/similar db type to the one you are working with.

      I have the feeling that I might help you.

      B. Roogards


      • #4
        This is what I ended up doing:

        I didn't need the WebSphere check and I was using c3p0 so I made a couple changes and ended up with this:

        public class OracleClobStringType extends ClobStringType {
        	private static OracleLobHandler oracleLobHandler = new OracleLobHandler();
        	static {
        		oracleLobHandler.setNativeJdbcExtractor(new C3P0NativeJdbcExtractor());
        	public OracleClobStringType() {
        		super(oracleLobHandler, LocalSessionFactoryBean.getConfigTimeTransactionManager());
        In addition so specifying @org.hibernate.annotations.Type on the field, I also had to change the field type from Clob to String. Works fine so far, but I feel like I'm missing something simpler.

        Edit: Oh, and because the field is now a String, the String <--> Clob converters in ApplicationConversionServiceFactoryBean are no longer necessary.


        • #5
          Here how it work for me

          I am using Oracle 10g with the thin driver (ojdbc14.jar) as well as Hibernate as a persistence mechnisim.

          CLOB now work well with roo transparently. Here my configuration :

          In the POJO class

          @Type(type = "text")
          private String bigUgeString;

          (The @Lob annotation resulted in truncation of my string)

          In the persistence.xml file located in src/main/java/resources/META-INF

          <?xml version="1.0" encoding="UTF-8" standalone="no"?>
          <persistence xmlns="" xmlns:xsi="" version="2.0" xsi:schemaLocation="">
          <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
          <provider>org.hibernate.ejb.HibernatePersistence </provider>
          <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
          <!-- value="update" to build a new database on each run; value="update" to modify an existing database; value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->
          <property name="" value="update"/>
          <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
          <property name="hibernate.connection.charSet" value="UTF-8"/>
          <property name="hibernate.c3p0.min_size" value="5" />
          <property name="hibernate.c3p0.max_size" value="100" />
          <property name="hibernate.c3p0.timeout" value="300" />
          <property name="hibernate.c3p0.max_statements" value="50" />
          <property name="hibernate.c3p0.idle_test period" value="3000" />
          <property name="hibernate.c3p0.idle_connection_test_period" value="300" />
          <property name="show_sql" value="true" />
          <property name="format_sql" value="true" />
          <property name="use_sql_comments" value="false" />
          <property name="hibernate.connection.SetBigStringTryClob" value="true"/>
          <property name="hibernate.jdbc.batch_size" value="0"/>

          <!-- Uncomment the following two properties for JBoss only -->
          <!-- property name="hibernate.validator.apply_to_ddl" value="false" /-->
          <!-- property name="hibernate.validator.autoregister_listeners" value="false" /-->

          Notice the two hibernate options in bold(the rest is irrelevant).

          And lastly the applicationContext.xml

          I edited the bean as follows :

          class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean"
          <property name="dataSource" ref="dataSource" />
          <!-- Ajouter pour supporter les BLOB et CLOB (Voir -->
          <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
          <property name="database" value="ORACLE" />


          I hope this can help.

          Best roo to all!

          Michel Bilodeau
          Last edited by directvox; Mar 10th, 2011, 01:04 PM. Reason: Typo