Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate-Interview-Questions what is an entity in hibernate?

Have Programming Question? Ask it here!
 
 
 


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


what is an entity in hibernate?


Advertisement
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.

Example:

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;

@Entity
@Table(name = "employee")
public class Employee {
    @Id
    @GeneratedValue
    @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;
    }

}


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com