vsharma
vsharma

Reputation: 309

HIbernate autoincrement not working

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

Upvotes: 3

Views: 458

Answers (2)

ash164
ash164

Reputation: 241

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

Upvotes: 0

PSR
PSR

Reputation: 40348

Yes,You need to add in database also

Example:

 SQL>field_name dataType NOT NULL AUTO_INCREMENT,

Upvotes: 2

Related Questions