Reputation: 325
I know, there are a lot of articles regarding the same issue, but still, I cannot figure it out why my code throws the above mentioned exception.
I am using JPA for database connection.
I have the following entity:
/**
* Primary key.
*/
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_REGISTRATION")
@SequenceGenerator(name = "SEQ_REGISTRATION", sequenceName = "SEQ_REGISTRATION")
private Long id;
As far as I know, in case of sequence generator, the default value is 50.
And I create my DB table sequence as follows:
--------------------------------------------------------
sequence for table REGISTRATION
--------------------------------------------------------
CREATE SEQUENCE "SEQ_REGISTRATION" MINVALUE 1 MAXVALUE
9999999999999999999999999999 INCREMENT BY 50 START WITH 1 CACHE 20 NOORDER
NOCYCLE;
I also tried to set the incrementy_by value larger, but it did not help.
Any ide why I keep getting contraint violation exception?
Thank you in advance!
Upvotes: 0
Views: 3761
Reputation: 5282
Unique constraint violated would imply that you already have existing records in the database and the sequence is configured to generate numbers that are already used, because it starts counting at 1.
You will need to adjust the "start with" to be at least one higher than the maximum value you currently have in the database.
Upvotes: 2