@GeneratedValue: Difference between revisions
Jump to navigation
Jump to search
Line 11: | Line 11: | ||
Used together with [[@Id]] when relying on the database to automatically generate the ID value, define "strategy = AUTO". | Used together with [[@Id]] when relying on the database to automatically generate the ID value, define "strategy = AUTO". | ||
=Cases= | |||
For a PostgreSQL table in which the primary key is: | |||
<syntaxhighlight lang='sql'> | |||
id BIGINT UNIQUE GENERATED ALWAYS AS IDENTITY, | |||
</syntaxhighlight> | |||
the corresponding annotation combination: | |||
<syntaxhighlight lang='java'> | |||
@Id | |||
@GeneratedValue(strategy=GenerationType.IDENTITY) | |||
private Long id; | |||
</syntaxhighlight> |
Revision as of 04:30, 19 October 2018
Internal
Overview
@GeneratedValue(strategy = GenerationType.AUTO)
Used together with @Id when relying on the database to automatically generate the ID value, define "strategy = AUTO".
Cases
For a PostgreSQL table in which the primary key is:
id BIGINT UNIQUE GENERATED ALWAYS AS IDENTITY,
the corresponding annotation combination:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;