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
is supported if hibernate.id.new_generator_mappings=true
is specified according to this article. I had the same problem as stated in this post, and I solved it following this recipe. Sequences are generated correctly now.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With