Hibernate / EclipseLink Interview questions
What is a JPA entity?
An entity is a plain Java class annotated with @Entity that represents a row (or set of rows, for inheritance hierarchies) in a database table. Every entity needs an identifier field marked with @Id, corresponding to the table's primary key.
@Entity @Table(name = "EMPLOYEE") public class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; @ManyToOne @JoinColumn(name = "DEPARTMENT_ID") private Department department; // getters and setters }
Beyond the class-level annotation and identifier, JPA requires entities to have a no-argument constructor, to not be declared final, and to expose persistent fields either directly or through accessor methods, so EclipseLink (or any provider) can construct, populate, and inspect instances reflectively.
More Related questions...