• Home
    Home This is where you can find all the blog posts throughout the site.
  • Categories
    Categories Displays a list of categories from this blog.
  • Bloggers
    Bloggers Search for your favorite blogger from this site.
  • Login


Posted by on in Hibernate
  • Setup the Development Environment for Hibernate
  • Hibernate distribution bundle
  • MySQL installed in your Computer
  • Setup the Database
  • To use simple database named "userdata" which has two tables named "users" and "tasks"
  • Create project Hibernate Example1
  • Create POJO Classes
  • Create class user
  • Create class task
  • Create Mapping Files
  • Hibernate needs to know how to load and store objects of the persistent class.
  • The mapping file tells Hibernate what table in the database it has to access, and what columns in that table it should use.
  • Create user.hbm.xml file
  • Tasks.java should also have a mapping file
  • Create task.hbm.xml file
  • Hibernate Configuration
  • Save it as hibernate.cfg.xml. Here you have to give the username and password according to your MySQL account. In my case username is root and there is no password
  • To startup Hibernate by creating a global org.hibernate.SessionFactory object and storing it somewhere for easy access in your application code
  • Create class HibernateUtil
  • A org.hibernate.SessionFactory is used to obtain org.hibernate.Session instances.
  • A org.hibernate.Session represents a single-threaded unit of work.
  • The org.hibernate.SessionFactory is a thread-safe global object that is instantiated once
  • Create class new

Users table
create table users(
id INT(10),
First_Name Varchar(100) Not Null,
Second_Name Varchar(100) Not Null
table table
create table tasks(
id INT(10),
user_id INT(10),
title Varchar(100) Not Null,
Descriptor  Varchar(100) Not Null
Continue reading
Hits: 1289 0 Comments

Posted by on in Hibernate


Hibernate is an open source java based library used to work with relational databases. Hibernate is an Object/Relational Mapping (ORM) tool for Java environments. The term Object/Relational Mapping (ORM) refers to the technique of mapping a data representation from an object model to a relational data model with a SQL-based schema. It is a very powerful ORM solution built on top of JDBC (Java Database Connectivity) API.

Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities. It can also significantly reduce development time otherwise spent with manual data handling in SQL and JDBC.


Continue reading
Hits: 1599 0 Comments

Posted by on in Hibernate
  • Create the java project example
  • Add jar files for hibernates
  • Create the Presistent class
  • Create the Mapping file for persistent class
  • Create the Configuration file
  • Create the class that retrieves or stores persistent object
  • Run the application

Employee .java

package com.tws;

public class Employee {
private int id;
private String firstName,lastName;

public int getId() {
return id;
public void setId(int id) {
this.id = id;
public String getFirstName() {
return firstName;
public void setFirstName(String firstName) {
this.firstName = firstName;
public String getLastName() {
return lastName;
public void setLastName(String lastName) {
this.lastName = lastName;


Continue reading
Hits: 1180 0 Comments