Hibernate生成类
我正在使用 hibernate 应用程序将数据存储在 Postgres 数据库中,我已经从 POJO 创建了 HBM 文件。该表由 ID 组成,该 ID 与 bigserial
相同,它应该自动生成。但是当我在插入记录后运行项目时,它不会增加 id 的值,因此会引发异常:
SEVERE: ERROR: duplicate key value violates unique constraint "usertable_pkey"
SEVERE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
我的 HBM 条目如下:
<id name="userid" type="long">
<column name="userid" />
<generator class="assigned" />
</id>
谁能建议我可以使用哪个生成器类来解决此问题?
I am using a hibernate application to store data in Postgres database I have created HBM file from POJO. The table consist of ID which is bigserial
identically it should be autogenerated. but when i run project after insertion of a record it doesnt increament value of id hence throws exception:
SEVERE: ERROR: duplicate key value violates unique constraint "usertable_pkey"
SEVERE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
My HBM entry is as follows:
<id name="userid" type="long">
<column name="userid" />
<generator class="assigned" />
</id>
Can anyone suggest which generator class I can use to resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您插入事务数据时,最好使用
[sequence][2]
来生成对象的 id。这将确保即使在多线程环境中,您也会为不同的对象获得不同的 id。
在此处阅读有关生成器类的 API 。
When you are inserting transactional data it is prefered to use a
[sequence][2]
to generate the id if the object.this will ensure that even in multi-threaded environments you will get different id for different objects.
Read the API about generator classes here.