Sobes.tech
Junior — Middle

What annotation is used for automatic generation of unique identifiers in a database?

sobes.tech AI

Answer from AI

In Java, the @GeneratedValue annotation along with @Id in JPA (Java Persistence API) is commonly used for automatic generation of unique identifiers in a database. For example:

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

The @GeneratedValue annotation indicates that the identifier value will be generated automatically, and the strategy parameter defines the generation strategy (e.g., IDENTITY, SEQUENCE, AUTO).

What annotation is used for automatic generation of… - sobes.tech