I am using Spring Boot 2 for creating microservices. I have a scenario to save an entity. In entity for Id column I have added like below
@Id
@GeneratedValue(Strategy=GenerationType.Auto, generator="increment")
@GenericGenerator(name="increment", strategy="increment")
@Column(name="Id", insertable=false)
private Integer id;
Above works sometimes and it throws Primary Key Constraint Violation Exception sometimes. It is not consistent though. I am running it as two instances with different ports.
Error I get is unique constraint violated:
ConstraintViolationException: could not execute statement; constraint [primary_key_cons]; nested exception is ConstraintViolationException.
Only option I have is to change the strategy to sequence.