Oracle 11g + Hibernate -> ORA-01461:只能为插入 LONG 列绑定 LONG 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16948246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle 11g + Hibernate -> ORA-01461: can bind a LONG value only for insert into a LONG column
提问by Revolit
There is an error in the log that says:
日志中有一个错误说:
ORA-01461: can bind a LONG value only for insert into a LONG column
ORA-01461: 只能为插入 LONG 列而绑定 LONG 值
no other useful info really. I tried to follow up on the code, google-d the problem and I think I might have found the problem, but unfortunately I do not have Oracle database or anything really (even the code isn't present to me, I'm writing all this from memory and notes :( ) So the only thing I can guess based on the code (and lots of googling) is the String mapping to varchar2. Some environment info:
真的没有其他有用的信息。我试图跟进代码,google-d 问题,我想我可能已经找到了问题,但不幸的是我没有 Oracle 数据库或任何真正的东西(即使我没有代码,我正在写所有这一切都来自记忆和笔记:() 所以我唯一能根据代码(和大量谷歌搜索)猜测的是字符串映射到 varchar2。一些环境信息:
Hibernate: 3.2.1.ga
Driver: ojdbc6-11.2.0.2.0.jar
Database: 11.2.0.2.0 - 64bit
The table has multiple varchar2(300 byte) and one varchar2(4000 byte), lets call this last one TEXT. I checked the entity, and in it's column annotation these fields have a restriction of 300 bytes to its value, even the TEXT (4000 byte) field! So that's one strange point. My wild guess is that a String comes, bigger then 300 BYTE, and this is the error that gets printed into the log when trying to persist (stack trace points where the code tries to persist an instance of this entity). Sadly I only have that log to go on.. :( Is my guess likely? Or it's going to be something else?
该表有多个 varchar2(300 字节)和一个 varchar2(4000 字节),我们称之为最后一个 TEXT。我检查了实体,在它的列注释中,这些字段的值限制为 300 字节,即使是 TEXT(4000 字节)字段!所以这是一个奇怪的点。我疯狂的猜测是一个字符串来了,大于 300 BYTE,这是尝试持久化时打印到日志中的错误(代码试图持久化该实体实例的堆栈跟踪点)。可悲的是,我只有那个日志要继续...... :( 我的猜测可能吗?或者它会是别的东西?
Here's the entity field:
这是实体字段:
@Column(name = "TEXT", nullable = false, length = varcharLength)
public String getText() {
return text;
}
Here is the create statement (the essential part anyway):
这是 create 语句(无论如何都是必不可少的部分):
CREATE TABLE "TABLENAME"
(
"ID" VARCHAR2(300 BYTE) NOT NULL ENABLE,
"VERSION" NUMBER(10,0),
"TEXT" VARCHAR2(4000 BYTE) NOT NULL ENABLE,
"PUBLISH_DATE" DATE NOT NULL ENABLE,
PRIMARY KEY ("ID")
);
(And the table has an index on PUBLISH_DATE, if that is relevant at all.)
(并且该表在 PUBLISH_DATE 上有一个索引,如果这完全相关的话。)
回答by Revolit
So, it was a problem with bigger String then 4000 byte. We changed the column to CLOB, this should solve it. And if the character literal is smaller then 4000 byte, it still gets stored in Oracle as if it would be varchar2(4000).
所以,这是一个更大的字符串然后是 4000 字节的问题。我们将列更改为 CLOB,这应该可以解决它。如果字符文字小于 4000 字节,它仍然会像 varchar2(4000) 一样存储在 Oracle 中。