Announcement Announcement Module
Collapse
No announcement yet.
Working with Clobs Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 (10.2.0.5)
    Hibernate 3.6.0.Final

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

    Code:
    @Column(name = "NOTES", columnDefinition = "CLOB")
    @Lob
    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:

    Code:
    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:

    Code:
    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?

    Thanks.

    - Luke

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

    Comment


    • #3
      Guys,

      Take a look to my article at http://viralpatel.net/blogs/2011/02/...-tutorial.html. 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
      jD

      Comment


      • #4
        This is what I ended up doing:

        http://forum.springsource.org/showpo...05&postcount=7

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

        Code:
        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.

        Comment


        • #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="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
          <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
          <provider>org.hibernate.ejb.HibernatePersistence </provider>
          <properties>
          <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="hibernate.hbm2ddl.auto" 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" /-->
          </properties>
          </persistence-unit>
          </persistence>


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

          And lastly the applicationContext.xml

          I edited the bean as follows :

          <bean
          class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean"
          id="entityManagerFactory">
          <property name="dataSource" ref="dataSource" />
          <!-- Ajouter pour supporter les BLOB et CLOB (Voir http://revetkn.com/?p=17) -->
          <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
          <property name="database" value="ORACLE" />
          </bean>

          </property>
          </bean>


          I hope this can help.

          Best roo to all!

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

          Comment

          Working...
          X