Hibernate supports a custom ID generator as noted in How to generate Custom Id in JPA
I was wondering, is there a JPA standard way of doing it?
Hibernate supports a custom ID generator as noted in How to generate Custom Id in JPA
I was wondering, is there a JPA standard way of doing it?
No, but you can write your own logic to assign primary key in a PrePersist
lifecycle callback method.
This can further be expanded to use an EntityListener
as noted in https://stackoverflow.com/a/54006736/242042 which allows you to inject Spring managed beans that your PrePersist
operation would require if the EntityListener
is managed by Spring.
If the EntityListener
is not managed by Spring, ThreadLocal may be an alternative (rel: Is it safe to pass in the Spring Application Context into a ThreadLocal associated with a request?)