Reputation: 1387
We using MYSQL and Hibernate for our project.
JPA is used to persist object in DB.
We have Multiple class with similar code
@Entity
@Table(name = "users")
class Users implement Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
.
.
.
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Now we want to give support for oracle too. How should we do it ? strategy=GenerationType.AUTO is not supported by oracle.
One soln is we can define sequence in each POJO which we do not want to do?
please provide us some input so that we can move ahead.
Upvotes: 1
Views: 1816
Reputation: 1387
@Id
@SequenceGenerator(name="admin_seq", sequenceName="unique_id")
@GeneratedValue(strategy=GenerationType.AUTO, generator="admin_seq")
private Long id
worked for me , thanks for all your answers
Upvotes: 1
Reputation: 691635
The AUTO strategy should work on Oracle as well. The difference with MySQL is that it will use a sequence instead of relying on an auto_increment ID.
You can even control the sequence name per entity if desired: see Hibernate sequence on oracle, @GeneratedValue(strategy = GenerationType.AUTO).
Upvotes: 2