Hibernate Classes

In this section, you will learn about persistent classes in Hibernate.



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

Hibernate Classes

In this section, you will learn about persistent classes in Hibernate.

Persistence classes are the POJO classes which is used to implement  entity of the business logic. (For example, Employee or Department in a payroll application).

After the addition of annotation, you don't need mapping XML file, you can directly do the mapping in the same entity class as given below :

package net.roseindia;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

public class User {
private Long id;

private String name;

private String password;

private String gender;

private String country;

private String aboutYou;

private Boolean mailingList;

@Column(name = "USER_ID")
public Long getId() {
return id;

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

@Size(min = 1, max = 50, message = "username must between 1 to 50 characters")
@Column(name = "USER_NAME", nullable = false, length = 50)
public String getName() {
return name;

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

@Size(min = 6, max = 10, message = "password must between 6 to 10 characters")
@Column(name = "USER_PASSWORD", nullable = false, length = 10)
public String getPassword() {
return password;

public void setPassword(String password) {
this.password = password;

@NotNull(message = "Please select a gender")
@Column(name = "USER_GENDER")
public String getGender() {
return gender;

public void setGender(String gender) {
this.gender = gender;

@NotNull(message = "Please select a country")
@Column(name = "USER_COUNTRY")
public String getCountry() {
return country;

public void setCountry(String country) {
this.country = country;

@Size(max = 100)
@Column(name = "USER_ABOUT_YOU", length = 100)
public String getAboutYou() {
return aboutYou;

public void setAboutYou(String aboutYou) {
this.aboutYou = aboutYou;

@Column(name = "USER_MAILING_LIST")
public Boolean getMailingList() {
return mailingList;

public void setMailingList(Boolean mailingList) {
this.mailingList = mailingList;

In the above example, you can see that the mapping and validation,both ,are done together using annotation.


Share on Google+Share on Google+

Hibernate Classes

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



Discuss: In this section, you will learn about persistent classes in Hibernate.  

Post your Comment

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