'Cannot save clob data type in database (Struts, Spring, Hibernate)

@Column(name="transpired")
@Lob
private String transpired;
public String getTranspired() {
    return transpired;
}
public void setTranspired(String transpired) {
    this.transpired = transpired;
}

I tried using the following code in our model class. Transpired is a field with long text messages (reports). When viewing the "report", it retrieves the data from the database and displays it correctly in our UI. However, when I'm saving (upon editing or creating) the report, the field save on the database is (null).

Any idea on how I could save long texts? We were using varchar2(4000) before but most reports are more than 4000 characters.

Thanks.

EDIT: I'm using Oracle 10g. Column type is CLOB.



Solution 1:[1]

Using oracle9i I faced the same problem and I couldn't solve it, I had to do it manually by JDBC, however in JPA its a piece of cake. I don't know if they solved it in hibernate or not, It was one year and a half ago :(

Solution 2:[2]

If want to insert the data through hibernate,add this below code in your springs XML

<property name="hibernate.connection.SetBigStringTryClob">true</property>
 <property name="hibernate.jdbc.batch_size">0</property>

or

<prop key="hibernate.connection.SetBigStringTryClob">true</prop>
 <prop key="hibernate.jdbc.batch_size">0</prop>

If you are intrested in adding through JDBC, add the following code in your data-source say Oracle-ds.xml for JBOSS

<connection-property name="SetBigStringTryClob">true</connection-property> 

Make sure that you use latest ojdbc14.jar and for JDBC connection and some jars like classes12.jar obstructs saving huge clob.So replace classes12.jar with ojdbc14.jar

This worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Omar Al Kababji
Solution 2