Search code examples
sqljpa-2.0playframework-2.0auto-increment

how to set H2 primary key id to auto_increment?


i am using sql, H2, and i am trying to make so that the ID of Usertable is auto_incremented. i tried all sql commands in H2 sql interface, didnot work out.

alter table user alter column int not null auto_increment;

this common one is even not working. is there any annotation of JPA for auto_incement may be?

thanks a lot


Solution

  • You should use the JPA annotations @Id and @GeneratedValue for your ID.

    Your SQL looks valid. Can you post the error message?