Reputation: 365
i have written a code for auto generated unique id as below for my sql data base,but in future my data base may change to oracle but i don't want to change my code again and again...is there any common code with common annotation for both oracle and my sql to auto generat a unique id.can any one help me?
@GeneratedValue(strategy = GenerationType.AUTO)
Thank you
Upvotes: 1
Views: 118
Reputation: 3364
@GeneratedValue(strategy = GenerationType.AUTO)
Should work for both mysql and Oracle without changing any code. You could also use the
@GeneratedValue(strategy = GenerationType.TABLE)
even that is not depends on the database. since these generators using basic sql operations in order to achive the results.
Upvotes: 1
Reputation: 386
If you know that you may have to support multiple types of databases, then using an ORM framework like Hibernate is a good option. It will decouple your code from database level instructions.
Upvotes: 0