I have a Springboot application that uses Spring Data. For test purposes only, I use an embedded H2 DB and load some initial data through a data.sql file. My entity are annotated with
@Id @GeneratedValue(strategy = GenerationType.AUTO) The problem I'm facing: for the generation of the ids (when I persist some objects), the id-values already used in my initial data (in data.sql) are NOT taken into consideration. As a result it comes to conflict, since it can happen that Hibernate try to use an Id already used. A solution would be to change the GenerationType into IDENTITY, but i'm reluctant to do so, since in production i would prefer having GenerationType.AUTO.
What is best practices to handle this?
AUTOoverIDENTITY. It seems to me that an identity/auto increment column is what you need here.