休眠自动递增ID [英] Hibernate Auto Increment ID
问题描述
我有一个j2ee应用程序,使用带注释的hibernate。我如何注释我的pojo类中的Id字段,将其设置为自动增量或自动生成。在添加bean的时候,我是否在我的bean中留下这个字段为null?
Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
,您将其保留为 null
( 0
)。 ( null
如果使用整数
/ Long
包装器)
在某些情况下, AUTO
策略已解析为 SEQUENCE
rathen比 IDENTITY
或 TABLE
,因此您可能需要手动将其设置为 IDENTITY 或
TABLE
(取决于底层数据库)。
SEQUENCE
+ 指定序列名称适用于您。
I have a j2ee application using hibernate with annotation. How do I annotate the Id field in my pojo class to set it as auto increment or auto generated. and in adding the bean do I leave that field in my bean null?
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
and you leave it null
(0
) when persisting. (null
if you use the Integer
/ Long
wrappers)
In some cases the AUTO
strategy is resolved to SEQUENCE
rathen than to IDENTITY
or TABLE
, so you might want to manually set it to IDENTITY
or TABLE
(depending on the underlying database).
It seems SEQUENCE
+ specifying the sequence name worked for you.
这篇关于休眠自动递增ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!