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
@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()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.