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

痞子三分冷 提交于 2019-12-06 14:42:41

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>

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!