无法在数据库中保存clob数据类型(Struts,Spring,Hibernate) [英] Cannot save clob data type in database (Struts, Spring, Hibernate)

查看:336
本文介绍了无法在数据库中保存clob数据类型(Struts,Spring,Hibernate)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我在模型类中使用了下面的代码。 Transpired是一个长文本消息(报告)的字段。查看报告时,它会从数据库中检索数据并在我们的用户界面中正确显示它。但是,当我在保存(编辑或创建时)报表时,数据库中的字段保存为(null)。



有关如何保存多长时间的任何想法文本?我们之前使用了varchar2(4000),但大多数报告都是超过4000个字符。



谢谢。 编辑:
我正在使用Oracle 10g。列类型为CLOB。

解决方案

Oracle提供的 POS 当您尝试保存超过4K时(保存更多的4K,对于cLob来说令人惊讶),CLOB字段默默无效。然而,假设在使用Oracle 10g JDBC驱动程序使用标准API(Hibernate所执行的操作)时可以工作(请参阅在Oracle 10g中处理Clobs )。令人惊讶的是,许多线程(例如这一个)提到了一个类似问题与旧版本的Oracle 10g瘦驱动程序,所以请确保您使用 Oracle 10g第2版驱动程序 (选取最新的ojdbc14.jar即10.2.0.4)或更高版本

请注意,Oracle有一个 CLK限制为32K 。为了克服这个限制,你需要将连接属性 SetBigStringTryClob 设置为 true 。根据各种消息来源,似乎您还需要禁用JDBC批处理(即将 batch_size 设置为 0 )。为此,请将以下属性添加到 hibernate.cfg.xml 中(或在您的Spring配置中) 。

 <! - 告诉Oracle允许CLOB大于32K  - > 
< property name =hibernate.connection.SetBigStringTryClob> true< / property>
< property name =hibernate.jdbc.batch_size> 0< / property>


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

解决方案

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>

这篇关于无法在数据库中保存clob数据类型(Struts,Spring,Hibernate)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆