what is an entity in hibernate?


what is an entity in hibernate?

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.



Related Tutorials/Questions & Answers:
What is the main feature of Hibernate3?
Feature of Hibernate3
what is an entity in hibernate?
Persistent Fields and Properties in Entity Classes
struts1.2,EJB3.0 and Hibernate3 integration example application - EJB
entity bean
Entity Relationship
Hibernate Entity
Hibernate 4 AnnotationSessionFactoryBean
entity hibernate
hibernate entity
An Entity Bean Example
Entity Relationship Diagram
Entity Relationship Diagram 3
Version of com.mtnfog>entity-model dependency
Version of com.pagerduty>entity-mapper_2.11 dependency
Version of com.mtnfog>entity-model dependency
Version of com.pagerduty>entity-mapper_2.10 dependency
What is Deck?
Hibernate Native Entity Query
XML error message: The reference to entity
Chapter 8. Entity Beans
creating entity bean in eclipse europa - EJB
Entity DB design pattern - Java Interview Questions
How to convert entity character to html character
Chapter 5. Client View of an Entity
Design and develop entity EJBs
Difference between JDBC , Entity Beans in EJB 3.0,Hibernate - EJB
Version of com.gu>content-entity-model_2.11 dependency
Version of com.gu>content-entity-thrift dependency
What is Hibernate in Java?