preeth
preeth

Reputation: 365

is there any common annotation for mysql and oracle for auto generated unique id to use in pojo?

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

Answers (2)

Mani
Mani

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

csn
csn

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

Related Questions