I have a Spring based application which uses JPA 2.1 for the persistence layer. I use @TableGenerator and @GeneratedValue annotations to handle my primary key id generation.
These are the annotations:
@TableGenerator(name = "user_gen", table = "id_gen", pkColumnName = "gen_name", valueColumnName = "gen_val", allocationSize = 1)
…
@GeneratedValue(strategy = GenerationType.TABLE, generator = "user_gen")
I use this entity to insert records in my user table. It was all working good. Now I have a new problem. An external application needs to insert records in my user tables. This causes primary key violation at my end.
Is there any option in JPA which will make my id_gen table's gen_val value updated based on the max id of my user table?
[I could not find such a solution in my research]
Other thoughts to fix the issue are also welcome.
Aucun commentaire:
Enregistrer un commentaire