Explain the role of the @Entity annotation in Hibernate.

The @Entity annotation marks a plain Java class as a persistent entity, telling Hibernate (and JPA) that instances of this class map to rows in a database table and can be saved, loaded, and queried through the persistence context.

Key Points

Example

Annotating a plain Employee class with @Entity and giving it an @Id field turns it from an ordinary POJO into something session.save(employee) can persist directly to an employee table.

@Entity
@Table(name = "employee")
public class Employee {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;
}

Interview Tip

A concise interview answer is

@Entity marks a POJO as a Hibernate-managed persistent class mapped to a database table. It has to be paired with an @Id field for the primary key, and it enables the class to be saved, loaded, and queried through the Session or JPA EntityManager.

Last updated: 16 July 2026

Previous question: What is the N+1 SELECT problem in Hibernate? How can it be prevented?

Next question: What is cascading in Hibernate?

More Hibernate (Optional) interview questions

All Hibernate (Optional) questions