[英]Hibernate JPA Generate id
I want that the primary key "puid" gets automatically generated.我希望自动生成主键“puid”。 However I the puid still is always 0. I tried different GeneratedValue variants (Sequence, Identity and Auto) but the result is the same.
但是我 puid 仍然总是 0。我尝试了不同的 GeneratedValue 变体(Sequence、Identity 和 Auto),但结果是一样的。
This is my code:这是我的代码:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long puid;
Does anyone have an idea how to fix that?有谁知道如何解决这个问题?
puid
has default value 0, when an object is just created. puid
默认值是 0,当对象刚创建时。puid
value manually, Hibernate doesn't change it. puid
值,Hibernate 不会更改它。 Just change long
to Long
to have null
initial value.long
更改为Long
即可获得null
初始值。@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long puid;
Use Wrapper object which supports null values as well.使用也支持空值的 Wrapper 对象。
Change long to Long将 long 更改为 Long
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.