生成的序列从1开始,而不是在注释中设置的1000 [英] Generated sequence starts with 1 instead of 1000 which is set in annotation
问题描述
我有这个注解 - 下面的代码 - 在我的实体类中,以便拥有个人合作伙伴表的序列。我期望序列以1000开头,因为我在部署期间使用import.sql将测试数据插入到我的数据库中,并且希望避免违反约束。但是当我想要保存数据比得到违反约束的异常时,它会通知我partner_id = 2已经存在的事实。它看起来像我错过了什么。
@Id
@Column(name =partner_id)
@SequenceGenerator(initialValue = 1000,
allocationSize = 1,
name =partner_sequence,
sequenceName =partner_sequence)
@GeneratedValue(generator =partner_sequence)
private long partnerId;
生成的序列如下所示:
CREATE SEQUENCE partner_sequence
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
ALTER TABLE partner_sequence
OWNER TO postgres;
我使用postgres 9.1。
我想念什么?这是我怎么接近我想要的?
感谢您提前提供任何帮助!
initialValue
和 alocattionSize
特定于 hilo
使用序列的算法。根据此
initialValue
甚至不被支持。我甚至没有看到Java层如何支持它,因为序列值是在数据库中生成的。
I would like to ask some help regarding database sequence created by Hibernate.
I have this annotation - the code below - in my entity class in order to have individual sequence for partners table. I expect that the sequence starts with 1000, because I insert test data into my database using import.sql during deploy and I would like to avoid the constraint violation. But when I want to persist data than I got the constraint violation exception and it informs me about the fact the partner_id = 2 already exists. It looks like I missed something.
@Id
@Column(name = "partner_id")
@SequenceGenerator(initialValue=1000,
allocationSize=1,
name = "partner_sequence",
sequenceName="partner_sequence")
@GeneratedValue(generator="partner_sequence")
private Long partnerId;
The generated sequence looks like this:
CREATE SEQUENCE partner_sequence
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
ALTER TABLE partner_sequence
OWNER TO postgres;
I use postgres 9.1.
Did I miss something? This is the way how can I approach what I want?
Thanks for any help in advance!
initialValue
and alocattionSize
are specific to hilo
algorithm that uses sequence. According to this initialValue
is not even supported. I don't even see how it could be supported from Java layer since sequence values are generated in the database.
Also see hibernate oracle sequence produces large gap
这篇关于生成的序列从1开始,而不是在注释中设置的1000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!