Issue
I am trying to create a entity class using Java record, but I get the error message "Entity does not have primary key" although I assigned an ID annotation.
import javax.persistence.*;
import java.time.LocalDate;
@Entity
public record Agent (
@Id
String code,
String name,
LocalDate date,
String workingArea,
String country,
String phoneNumber,
boolean licenseToKill,
int credits,
byte[] picture)
{}
What's wrong with this?
Solution
A record
cannot be used as Hibernate entity because it breaks the requirements of an entity according to JPA specification. Make it class
and use @Immutable
annotation instead:
@Entity
@Immutable
public class Agent
Answered By - gkatiforis