dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Mar 9, 2020

How to Define an Auto-incremented Identifier via JPA Annotations

For defining an auto-incremented identifier in an entity, we need the @Id annotation and the IDENTITY generator as follows:

@Entity
public class User implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    ...
}
Octavia Anghel
 
Thanks for your registration, follow us on our social networks to keep up-to-date