3

If I'm using hibernate Pojo class using annotations as below - as I'm using GenerationType.AUTO

@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; 

Is there any need to add "auto-increment" in database side also for an entity...?

2 Answers 2

2

Yes,You need to add in database also

Example:

 SQL>field_name dataType NOT NULL AUTO_INCREMENT, 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanx for the quick reply. I mean if i dont want to add auto increment explicitly in Database side then how it can be possible with hibernate in Pojo with annotations..?
0

You can use other generator types for that like table or sequence generators. You will not have to "auto-increment" in the column. But there will be a change in the Pojo class and you will have to create sequence in your DB.

Please refer below link for different types of generator- HIbernate id generators

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.