I would like to have native and portable id generation on my JPA 2 entities, currently running Hibernate and MySQL
When using @GeneratedValue(strategy=AUTO), hibernate defaults to the "hibernate_sequence" table on MySQL, i would like IDENTITY
If i solve it using @GeneratedValue(strategy=IDENTITY), i loose Oracle/Postgres portability
How can i set Hibernate to use IDENTITY as default for mysql when @GeneratedValue strategy=AUTO?
You can write your own custom generator and maybe invoke a function/stored procedure on your
DB to create the identity you need.
Take a look here , this is a blog with nice example about how to do what I just wrote.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With