Reputation: 47
I want that the primary key "puid" gets automatically generated. However I the puid still is always 0. I tried different GeneratedValue variants (Sequence, Identity and Auto) but the result is the same.
This is my code:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long puid;
Does anyone have an idea how to fix that?
Upvotes: 1
Views: 1070
Reputation: 15878
Use Wrapper object which supports null values as well.
Change long to Long
Upvotes: 2
Reputation: 19956
puid
has default value 0, when an object is just created.puid
value manually, Hibernate doesn't change it.
Just change long
to Long
to have null
initial value.@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long puid;
Upvotes: 4