Explain the persistence class in hibernate?

Explain the persistence class in hibernate?

What is persistence class in hibernate?

View Answers

June 8, 2012 at 6:49 PM

Persistence class are simple POJO classes in an application. It works as implementation of the business application for example Employee , department etc. It is not necessary that all instances of persistence class are defined persistence.

Example:

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;
    }

}

Description: The javax.persistence package contains the classes and interfaces that is used to define the relationship between persistence provider and the managed classes the client of java persistence API.


June 9, 2012 at 2:42 AM

The entire concept of Hibernate is to take the values from Java class attributes and persist them to a database table. A mapping document helps Hibernate in determining how to pull the values from the classes and map them with table and associated fields.

Java classes whose objects or instances will be stored in database tables are called persistent classes in Hibernate. Hibernate works best if these classes follow some simple rules, also known as the Plain Old Java Object (POJO) programming model. There are following main rules of persistent classes, however, none of these rules are hard requirements.

All Java classes that will be persisted need a default constructor.

All classes should contain an ID in order to allow easy identification of your objects within Hibernate and the database. This property maps to the primary key column of a database table.

All attributes that will be persisted should be declared private and have getXXX and setXXX methods defined in the JavaBean style.

A central feature of Hibernate, proxies, depends upon the persistent class being either non-final, or the implementation of an interface that declares all public methods.

All classes that do not extend or implement some specialized classes and interfaces required by the EJB framework.

The POJO name is used to emphasize that a given object is an ordinary Java Object, not a special object, and in particular not an Enterprise JavaBean.

Based on the few rules mentioned above we can define a POJO class as follows:









Related Tutorials/Questions & Answers:
Explain the persistence class in hibernate?
Explain Transparent Persistence - Hibernate
Advertisements
Explain final class, abstract class and super class.
Explain the parameters of Font class constructor.
Feature of Hibernate3
persistence xml class element
What is the main feature of Hibernate3?
Maven Repository/Dependency: org.grails.plugins | hibernate5
Maven Repository/Dependency: hibernate | hibernate3
struts1.2,EJB3.0 and Hibernate3 integration example application - EJB
Maven dependency for org.grails.plugins - hibernate5 version 7.0.6 is released. Learn to use hibernate5 version 7.0.6 in Maven based Java projects
Maven dependency for org.grails.plugins - hibernate5 version 7.0.7 is released. Learn to use hibernate5 version 7.0.7 in Maven based Java projects
Maven dependency for org.grails.plugins - hibernate5 version 7.0.5 is released. Learn to use hibernate5 version 7.0.5 in Maven based Java projects
Explain - LDAP
please explain this program
Explain ServletContext.
Explain WML
class loaders
class
explain this method
can any one explain this
please explain this prog
Explain normalization concept?
Explain unescape() and escape() in JavaScript?
class
Class
Explain factories design?
Please explain the logic....
Developing Login Action Class
ModuleNotFoundError: No module named 'explain'
What is Action Class?
Explain types of java programs
What is a vector in Java? Explain with example.
please explain this prog
Explain struts.jar file - Struts
Please explain Hibernate Sessionfactory.
Explain push and pop
what is the meaning of this or explain this
explain servletconfig with programiing example?
Please explain @interface with an example
Please explain @interface with an example
Explain Hibernate Relationships with example.
Transparent Persistence - Hibernate Interview Questions
Explain Linked List
Please explain me the flow of this program..
can you explain ?
Explain about Type Juggling in php?
Explain the ternary conditional operator in PHP?
What is outer join?Explain with examples.
Explain about Cross site scripting?

Ads