Hibernate 和 ORA-01400: 无法插入 NULL
我有一个相当简单的场景,一个表,一个用于自动生成主键的序列:
CREATE TABLE foo (event_id NUMBER(19,0)....
CREATE SEQUENCE event_seq
休眠映射的一部分如下所示:
...
<id name="id" column="EVENT_ID" type="long">
<generator class="native">
<param name="sequence">event_seq</param>
</generator>
</id>
...
长时间运行良好,没有问题。但最近我得到了这个:
ORA-01400: cannot insert NULL into ("TESTING"."FOO"."EVENT_ID")
这是否意味着 Oracle 无法生成 EVENT_ID 的序列号? 这可能是什么原因?显然这个错误来自 64 位 Oracle,这可能与问题有关吗?删除并重新创建表和序列没有帮助,它只是不想在该特定机器上工作。无论我做什么,我都无法重现此错误,该错误来自几乎无法访问的用户之一。
有什么想法吗?
<强>-------------- 问题解决了 ---------------
最初的问题是在 32 位操作系统上使用驱动程序 10.2.0.1.0 时使用 Oracle 10.2.0.1.0 64 位检测到的。一旦驱动程序更新到11.2.0.2.0,问题就消失了。这完全取决于 VM 是作为 32 位还是 64 位系统运行。
I've got fairly simple scenario, one table, one sequence for auto-generating primary keys :
CREATE TABLE foo (event_id NUMBER(19,0)....
CREATE SEQUENCE event_seq
Part of the hibernate mapping looks like this:
...
<id name="id" column="EVENT_ID" type="long">
<generator class="native">
<param name="sequence">event_seq</param>
</generator>
</id>
...
Works well without a problem for a long time. But recently I've got this :
ORA-01400: cannot insert NULL into ("TESTING"."FOO"."EVENT_ID")
Would that mean that Oracle failed to generate the sequence number for the EVENT_ID?
What could be a reason for this? Apparently this error came from 64bit Oracle, could it be related to a problem? Dropping and recreating the table and sequence doesn't help, it just doesn't want to work on that particular machine. No matter what I do, I can't reproduce this, the error comes from one of the users which is pretty much unreachable.
Any ideas?
---------------
Problem solved
---------------
The original issue was detected with Oracle 10.2.0.1.0 64bit while using driver 10.2.0.1.0 on 32bit OS. Once the driver was updated to 11.2.0.2.0, the problem disappeared. It all depends on the VM's if they are running as 32bit or 64bit system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Oracle 不会在表插入时自动生成序列号。您要么必须将其编码到插入中,要么将其编码到触发器中,要么让 hibernate 执行此操作。
我认为 hibernate 需要
如果你希望它这样做或者你的 hibernate 设置已经不再认为你正在处理 Oracle 数据库Oracle doesn't automatically generate sequence numbers on table inserts. You either have to code it into the insert, code it into a trigger or have hibernate do it.
I think hibernate needs
<generator class="sequence">
if you want it to do it or your hibernate setup has stopped thinking you are dealing with an Oracle database