开发者

Hibernate and ORA-01400: cannot insert NULL

开发者 https://www.devze.com 2023-03-05 12:35 出处:网络
I\'ve got fairly simple scenario, one table, one sequence for auto-generating primary keys : CREATE TABLE foo (event_id NUMBER(19,0)....

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开发者_如何学Python 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号