After some days of researching and looking for information and according to my info, you only can choose a generation strategy using annotations: for example GenerationType.SEQUENCE
or GenerationType.IDENTITY
. In case of MySQL the best seems to be GenerationType.IDENTITY
, but in case of Oracle it’s GenerationType.SEQUENCE
.
So, what happen if you want the application to run with Oracle and MySQL? I’ve only found two ways: since Oracle 12c you can use GenerationType.IDENTITY
(but anyway the sequences seems to be a better strategy), and the other way is using persistence.xml and externalize orm.xml to overrride the strategy annotation configuration.
I’ve not tested this last option because I think it’s dangerous and error proning. Why it’s not simply possible to have a sort of GenerationType.COMPATIBLE
which would decide the best strategy for every database(sequences for Oracle and autoincrements for MySQL? Am I missing something?