I use this code to generate a unique key for my Entities
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
I used to use other methods, but it’s really important in my application to be able to insert database entries from other programs too.
The IDENTITY way is the only way I could figure out how to make it so I didn’t have to worry about the incrementer logic or what not.
Are there any other strategies?
You can create sequention on your DB and then you can use follow construction: