【发布时间】:2011-03-25 20:43:14
【问题描述】:
我正在使用 hibernate 的“增量”生成器来生成我的自动增量 ID。这工作正常,直到我不得不添加另一个应用程序,它也使用“增量”生成器来生成新的 id。我意识到增量生成器有一个问题:
"generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster."
有没有办法使用休眠来解决这个问题?或者我是否必须编写额外的代码来锁定表,检查数据库的最大 ID(然后增加它),最后释放锁?使用一种休眠配置不是一种选择。此外,我无法将 auto_increment 选项添加到 db 表中,因为我们在表上有多个键。
欢迎任何建议,我猜这是一个常见问题。
【问题讨论】:
标签: java hibernate auto-increment