I am using hibernate with a MySQL database in my spring MVC project. I used the @GeneratedValue annotation to set auto-incremenet in my id fields. So, all of my entities have this piece of code, and everything works as expected:
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "id") private Integer id; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; }
At this time, I want to switch to the Oracle database. Now I have two questions:
1. What is the best solution to set auto-increment field in oracle? I used this code but does not work:
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_Sequence") @SequenceGenerator(name="id_Sequence", allocationSize=1)
2 (More important question). Can I use a unique annotation to set auto-increment, which will work for both MySQL and Oracle ?
source share