We need a class to be declared as an entity for hibernate to use it. Hibernate considers the class as a persistent class if it is annotated with the
@Entity
annotation.
Perform the following steps to declare a class as a hibernate entity:
Enter the following code on your editor:
@Entity public class Employee { // Fields and getter/setter }
Here, we annotate a class,
Employee
, with the@Entity
annotation. As a result, hibernate considers the current class eligible to be persisted.If we want a user-defined table name rather than a default name, we can use the
@Table
annotation. The following code shows us how to achieve this:@Entity @Table(name="tbl_employee") public class Employee { // Fields and getter/setter ...