ratna rathor
what is an entity in hibernate?
2 Answer(s)      3 years and 6 months ago
Posted in : Hibernate Interview Questions

what is an entity in hibernate?

View Answers

June 8, 2012 at 6:41 PM

Entity: In general entity is an object that has some distinct value. In a persistent storage mechanism, an entity is a business object. Each entity has an associated table in relational database. Each instance of the entity represents a row of the table.

Entity class is an annotated POJO (Plain Old java Object). Here are some points to be noted during writing entity class:

Class must have constructor

Create getter setter for each field

Don?t define any field static or final.


Here is an entity class named Employee.java.It mapped the employee table.

package net.roseindia.table;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Table(name = "employee")
public class Employee {
    @Column(name = "emp_id")
    private int id;

    @Column(name = "name")
    private String name;

    @Column(name = "salary")
    private int salary;

    @Column(name = "date_of_join")
    private Date dateOfJoin;

    public int getId() {
        return id;

    public void setId(int id) {
        this.id = id;

    public String getName() {
        return name;

    public void setName(String name) {
        this.name = name;

    public int getSalary() {
        return salary;

    public void setSalary(int salary) {
        this.salary = salary;

    public Date getDateOfJoin() {
        return dateOfJoin;

    public void setDateOfJoin(Date dateOfJoin) {
        this.dateOfJoin = dateOfJoin;


August 15, 2015 at 6:18 AM


Check the example code at entity in Hibernate page.