数据库未返回本机生成的标识值
我正在使用 IBM DB2 V 9.1.0.356。我使用的是 DB2 JDBC 驱动程序版本 9.7。
我正在将这些技术用于我的应用程序。
Spring MVC、Hibernate、DB2、Websphere
在我的创建表脚本中; ID 列生成为:
ID BIGINT GENERATED BY DEFAULT AS IDENTITY
在 Java 实体类中,其配置为:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column( name = "id", nullable = false )
当我通过 hibernate 调用它来保存和对象时:
*.save(persistentObject);
数据被保存。但我遇到了以下异常:
org.hibernate.HibernateException: The database returned no natively generated identity value
at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(IdentifierGeneratorFactory.java:90)
注意:我的应用程序配置在不同计算机上的两台服务器上。从一台机器我可以成功保存数据;但从其他方面我得到了上述例外。
I am using IBM DB2 V 9.1.0.356. I am using DB2 JDBC driver version 9.7.
I am using these technologies for my application.
Spring MVC, Hibernate, DB2, Websphere
In my Create Table script; ID column is generated as:
ID BIGINT GENERATED BY DEFAULT AS IDENTITY
In Java Entity class its configured as:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column( name = "id", nullable = false )
When I saves and object by calling this through hibernate:
*.save(persistentObject);
Data is saved. But I got following Exception:
org.hibernate.HibernateException: The database returned no natively generated identity value
at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(IdentifierGeneratorFactory.java:90)
Note: My application is configured on two servers on different machines. From one machine I can succefully save data; but from other I got above mentioned exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尽管它们都连接到同一个数据库,但它在一台 WebSphere 服务器上有效,而在另一台服务器上失败,这一事实表明 JDBC 驱动程序的版本存在问题。我会先检查一下。
The fact that this works on one WebSphere server and fails on another although they both connect to the same database suggests that there is an issue with the version of the JDBC driver. I would check that first.
如果@id注解的属性映射列不支持自动生成id,也会出现上述异常。
即
使用
可能会解决问题。
The above Exception can also occur if the @id annotated property mapped column dose not support auto generation of id.
i.e.
using
might solve the problem.
确保在创建表时 id 字段应标记为自动增量,然后使用
Make sure that while creating your table id field should be marked as auto-increment and then use
检查数据库中的主键,如果它不是自动增量那么你会得到这个错误。
在此处输入图片说明
check primary key in database, if it is not auto increment then you will get this error.
enter image description here