无法在数据库中保存 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 是一个包含长文本消息(报告)的字段。当查看“报告”时,它会从数据库中检索数据并将其正确显示在我们的 UI 中。但是,当我保存(编辑或创建)报告时,数据库中保存的字段为(空)。
知道如何保存长文本吗?我们之前使用 varchar2(4000),但大多数报告都超过 4000 个字符。
谢谢。
编辑: 我使用的是Oracle 10g。列类型为 CLOB。
@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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
众所周知,Oracle 提供的
POS瘦驱动程序会在您尝试保存超过 4K 时自动静默地使 CLOB 字段无效(保存超过 4K,这对于 cLob 来说是惊人的)。然而,当使用标准 API(Hibernate 所做的)和 Oracle 10g JDBC 驱动程序时,这应该可以工作(请参阅 在 Oracle 10g 中处理 Clob)。令人惊讶的是,许多线程(例如这个)提到了类似的旧版本的 Oracle 10g 瘦驱动程序存在问题,因此请确保使用 Oracle 10g 第 2 版驱动程序(获取最新的 ojdbc14.jar,即 10.2.0.4)或更高版本。请注意,Oracle 有 32K 的限制对于 CLOB。要克服此限制,您需要将连接属性
SetBigStringTryClob
设置为true
。根据各种来源,您似乎还需要禁用 JDBC 批处理(即将batch_size
设置为0
)。为此,请将以下属性添加到您的 hibernate.cfg.xml(或 Spring 配置中)。
The
POSthin 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
totrue
. According to various sources, it seems that you will also need to disable JDBC batching (i.e. setbatch_size
to0
).To do so, add the following properties to your
hibernate.cfg.xml
(or in your Spring configuration).使用oracle9i我遇到了同样的问题并且无法解决它,我必须通过JDBC手动完成,但是在JPA中这是小菜一碟。我不知道他们是否在休眠状态下解决了这个问题,那是一年半前了:(
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 :(
如果想通过 hibernate 插入数据,请在 springs XML 中添加以下代码
,或者
如果您有兴趣通过 JDBC 添加,请在数据源中添加以下代码,例如 JBOSS 的 Oracle-ds.xml
确保您使用最新的ojdbc14.jar 和 JDBC 连接以及一些 jars,如classes12.jar 会阻碍保存巨大的 clob。所以用 ojdbc14.jar 替换classes12.jar
这对我有用。
If want to insert the data through hibernate,add this below code in your springs XML
or
If you are intrested in adding through JDBC, add the following code in your data-source say Oracle-ds.xml for JBOSS
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.