如何使用现有的Oracle序列在hibernate中生成id? [英] How to use existing Oracle sequence to generate id in hibernate?
问题描述
我有一个名为 PRODUCT_ID_SEQ
的遗留Oracle数据库。
以下是我需要生成正确ID的 Product
类的映射:
public class Product {
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator =retailerRaw_seq)
@SequenceGenerator (name =retailerRaw_seq,
sequenceName =PRODUCT_ID_SEQ)
private Long ID;
...
}
但看起来像ids生成间隔为50,如1000,1050,1100等。这对应于默认值 allocationSize
property = 50.这意味着Hibernate并没有实际使用已经在db中定义的序列。
我如何让Hibernate使用这个序列? 回答原始问题:
@SequenceGenerator(name =EL_SEQ,sequenceName =EL_SEQ,allocationSize = 1)
设置值为增量的 allocationSize
通过。
I have legacy Oracle db with a sequence named PRODUCT_ID_SEQ
.
Here is the mapping of Product
class for which I need generate correct ids:
public class Product {
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "retailerRaw_seq")
@SequenceGenerator(name = "retailerRaw_seq",
sequenceName = "PRODUCT_ID_SEQ")
private Long id;
...
}
But looks like ids are generated with an interval of 50, like 1000, 1050, 1100 etc. This corresponds to the default value of allocationSize
property = 50. So that means that Hibernate doesn't actually use the sequence which is already defined in the db.
How do I make Hibernate use the sequence?
The answer to the original question:
@SequenceGenerator(name="EL_SEQ", sequenceName="EL_SEQ",allocationSize=1)
It is allocationSize
that sets the value to increment by.
这篇关于如何使用现有的Oracle序列在hibernate中生成id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!