@GeneratedValue: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
Line 10: Line 10:
</syntaxhighlight>
</syntaxhighlight>


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". This declaration works with an [[H2]] database.


=Cases=
=Cases=

Latest revision as of 20:07, 10 November 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". This declaration works with an H2 database.

Cases

For a PostgreSQL table in which the primary key was declared as follows:

id BIGINT UNIQUE GENERATED ALWAYS AS IDENTITY,

the corresponding annotation combination that works is:

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;