Hibernate create POJO classes

In this tutorial you will learn how to create a POJO class in Hibernate.

Ads

Tutorials   
How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate 4.3.4 Released: Hibernate 4.3.4.Final Maven dependency Hibernate 4.3 Hello World: Example How to create SessionFactory in Hibernate 4.3.1? Hibernate 4 Hello World: Example of Hello World program Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4 Hibernate 4.3 and JPA 2.1 Example What is Hibernate in Java? Hibernate Overview and Architecture What is JPA 2.1? Hibernate 4.3.0.Final Maven dependency Hibernate 4.3 ORM Features Hibernate 4.3 Tutorial Hibernate Criteria average example Hibernate Criteria load all objects from table Hibernate Criteria Hibernate beginner tutorial Hibernate Session.delete() Example Hibernate save or update method example Hibernate Load Example Hibernate save Example - Rose India Hibernate 4 tutorials Hibernate Example Step by Step in Eclipse Hibernate Configuration files Setup Hibernate Environment Hibernate Architecture Hibernate Overview Hibernate 4.2 Tutorial Hibernate 4 Annotations Tutorial Hibernate 4 AnnotationSessionFactoryBean hibernate versions hibernate jndi hibernate tomcat hibernate metamodel generator hibernate entity Seam Hibernate C3P0 Hibernate hibernate shard hibernate means temporal hibernate jsf hibernate spring j2ee hibernate spring hibernate encrypted password alias_to_entity_map hibernate temporal jsf spring hibernate hibernate by example hibernate repository hibernate sample code
Ads

Hibernate create POJO classes

In this tutorial you will learn how to create a POJO class in Hibernate.

POJO (Plain Old Java Object) is a programming model that follow some simple rules (not required to follow these rules hardly) to create a classes that implements the entities of the business problem. These can be as follows :

  • Implement a default (no-argument) constructor : There must be a default constructor in a POJO class that are instantiated by the Hibernate using the Constructor.newInstance()
  • Give(optional) an identifier property : It is an optional property that you can provide in POJO class because it is mapped as a primary key in the database table however, if you don't give this property Hibernate will maintain the track of object identifiers internally. Type of id can be of any primitive type.
  • Should be prefer(optional) a non-final classes : Declaring a final class as well as public final methods should be avoidable because hibernate's feature proxies depends upon the POJO classes. If you would like to use a public final method with a class you must have to disable the proxying by setting lazy='false' explicitly at the time of use of proxies for lazy association fetching.
  • Declare a setter and getter methods with their field names.

Example :

Here I am giving an example of POJO class. This class contains some fields using which I have created setter and getter methods. I have also created a default constructor. A simple dummy POJO class example is as follows :

package roseindia;

public class Employee
{
private long empId;
private String empName;
public Employee() {

}

public Employee(String empName) {
this.empName = empName;
}
public long getEmpId() {
return this.empId;
}
public void setEmpId(long empId) {
this.empId = empId;
}
public String getEmpName() {
return this.empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
}

Advertisements

Ads
Share on Google+Share on Google+

Hibernate create POJO classes

Posted on: February 16, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Hibernate create POJO classes  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads