如何将H2主键ID设置为auto_increment? [英] how to set H2 primary key id to auto_increment?

查看:1198
本文介绍了如何将H2主键ID设置为auto_increment?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用sql,H2,并且正在尝试使Usertable的ID自动递增.我在H2 sql界面中尝试了所有sql命令,但没有解决.

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;

这种常见的方法甚至无法正常工作. JPA的auto_incement可能有任何注释吗?

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

非常感谢

推荐答案

您应该使用JPA批注@Id@GeneratedValue作为ID.

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

您的SQL看起来有效.您可以发布错误消息吗?

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

这篇关于如何将H2主键ID设置为auto_increment?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆