1

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.

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

Comments

1
@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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.