Reputation: 2393
I need to persist()
an object with an id
, that I can specify. However I can't annotate the base class with a different @GeneratedValue
. Can you assign a value generator just for a single persist? I have a specific use, please don't tell me that the id shouldn't be set manually.
Is there a way this can be done with JPA? Appreciate any hints!
[edited] @GeneratedValue
annotation is present in the base class
Upvotes: 0
Views: 75
Reputation: 691635
@GeneratedValue
is precisely used to tell JPA that it should generate the ID. If you want to assign the ID explicitely and don't want JPA to generate one for you, just don't use the @GeneratedValue
annotation, assign the ID explicitely, and call persist()
.
Upvotes: 2