JPA/Hibernate 对 Oracle 序列的增量过多
我在我的 Java 项目上使用 Hibernate,我有 Oracle DB。在 ID 列中,我标识了一个增量为 1 的序列。但这就是 JPA/Hibernate 从序列中获取 nextVal 的方式:
1 1451
2 1450
3 1402
4 1401
5 1400
6 1352
7 1351
8 1350
9 426
您可以看到 nextVal 有时会获取 1,但大多数情况下会获取 50 或更多。即使我将起始值设置为 1,我什至看到序列的开头为 200。为什么会发生这种情况?这是正常的吗?
我可以以某种方式减少这个“50”增量吗?
I use Hibernate on my Java project, I have Oracle DB. An ID column, I identified a sequence with increment 1. But this is how JPA/Hibernate gets nextVal from the sequence:
1 1451
2 1450
3 1402
4 1401
5 1400
6 1352
7 1351
8 1350
9 426
You can see that nextVal sometimes get 1, but mostly 50 or more. I see even the start of a sequence 200 even though I put the start value 1. Why is this happening? Is this normal?
Can I reduce this "50" increment somehow?
Edit: Duplicate of hibernate oracle sequence produces large gap
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了这个解决方案;
allocationSize=1
”添加到@Id
属性的注释@SequenceGenerator
中,如所描述的那样此处:https://stackoverflow.com/a/5346701/169534问题已解决
I found this solution;
allocationSize=1
" to annotation@SequenceGenerator
of@Id
property as it was described here: https://stackoverflow.com/a/5346701/169534Problem resolved
如果您的序列的缓存大小为 50,并且数据库在从序列中提取数据之间关闭,您可能会遇到此问题。当数据库关闭时,剩余的缓存值将永远不会被使用。
If your sequence has a cache size of 50 you might see this issue if the database is getting shutdown in between your fetches from the sequence. The remaining cached values will never be used when the database gets shutdown.