views:

619

answers:

2
@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.

A: 

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

Omar Al Kababji
It's not a problem in hibernate, it's a problem in Oracle's thin driver (that should be solved when using Oracle 10g Release 2 drivers or later).
Pascal Thivent
+2  A: 

The POS thin drivers that Oracle delivers are well known to automatically and silently nullify CLOB-fields when you try to save more than 4K (saving more that 4K, amazing for cLob). This is however supposed to be working when using the standard APIs - which Hibernate does - with Oracle 10g JDBC driver (see Handling Clobs in Oracle 10g). Surprisingly, many threads (e.g. this one) mention a similar problem with old versions of Oracle 10g thin driver so make sure that you use Oracle 10g Release 2 drivers (pick up the most recent ojdbc14.jar i.e. 10.2.0.4) or later.

Note that Oracle has a limitation of 32K for CLOBs. To overcome this limitation, you'll need to the set the connection property SetBigStringTryClob to true. According to various sources, it seems that you will also need to disable JDBC batching (i.e. set batch_size to 0).

To do so, add the following properties to your hibernate.cfg.xml (or in your Spring configuration).

<!-- Tell Oracle to allow CLOBs larger than 32K -->
<property name="hibernate.connection.SetBigStringTryClob">true</property>
<property name="hibernate.jdbc.batch_size">0</property>
Pascal Thivent
Will try to do this. Thanks :)
ASC
It worked! THANKS!!! :)
ASC
You're welcome. Glad to see it makes you happy :)
Pascal Thivent