SlideShare a Scribd company logo
1 of 3
Download to read offline
What is Hibernate?
This tutorial explains what Hibernate is and will show some examples why it is useful to use
Hibernate.

Generals
Author:
Sebastian Hennebrueder
http://www.laliluna.de/tutorials.html Tutorials for Struts, EJB, xdoclet, JSF, JSP and
eclipse.
Date:
February, 25th 2005

PDF Version des Tutorials:
http://www.laliluna.de/assets/tutorials/what-is-hibernate-tutorial-en.pdf



Main features
Hibernate is a solution for object relational mapping and a persistence management
solution or persistent layer. This is probably not understandable for anybody learning
Hibernate.

What you can imagine is probably that you have your application with some functions
(business logic) and you want to save data in a database. When you use Java all the
business logic normally works with objects of different class types. Your database tables
are not at all objects.

Hibernate provides a solution to map database tables to a class. It copies the database
data to a class. In the other direction it supports to save objects to the database. In this
process the object is transformed to one or more tables.

Saving data to a storage is called persistence. And the copying of tables to objects and
vice versa is called object relational mapping.


Why using Object Relational Mapping?
Better system architecture
When you include all functionality of your application and the access to the database
within your dialogs, you will have some severe disadvantages.

It is really difficult to reuse code. You will repeat code at many places. If you change
anything it is quite hard to find out all places where you have to add changes.

When you separate your dialogs from your logic and the logic from the persistence
mechanism you can more easily apply changes to one part without influencing the other
parts.

Reduce time for standard DB actions
Most queries in database development are simple “insert, update, delete” statements.
There is no need to develop all these tedious statements. Hibernate helps you save time.
Loading classes from the database looks like
Query query = session.createQuery("select b from Bug as b");
      for (Iterator iter = query.iterate(); iter.hasNext();) {
        bugs.add((Bug) iter.next());
      }
    return bugs;
saving a class “bug” to the database looks like
session.update(bug);



Advanced features difficult to develop yourself
Caching solutions, transactions and other features Hibernate provides are not so easy to
implement. It is actually non sense to develop something which allready exist.
Using Hibernate everything is there. You just have to use it.

How Hibernate works
What is nice and in my opinion an advantage over entity beans, hibernate starts from simple java
classes (Pojo = Plain Old Java Objects).
To use hibernate you will create a simple java class:
public class Bug
    implements Serializable
{
    private int hashValue = 0;
    private java.lang.Integer id;
    private java.lang.String title;

    public Bug()
    {
    }
    public Bug(java.lang.Integer fid)
    {
        this.setId(fid);
    }
    public java.lang.Integer getId() {
      return id;
    }
    public void setId(java.lang.Integer id) {
      this.id = id;
    }
    public java.lang.String getTitle() {
      return title;
    }
    public void setTitle(java.lang.String title) {
      this.title = title;
    }
.............


Than you create a mapping file. The mapping file explains Hibernate which field in the class is
mapped to which field in the database.


<hibernate-mapping package="de.laliluna.fehlerbehebung">
    <class name="Bug" table="bug">
        <id name="id" column="fid" type="java.lang.Integer">
            <generator class="sequence">
              <param name="sequence">public.bug_fid_seq</param>
            </generator>
        </id>
        <property name="title" column="ftitle" type="java.lang.String" />
</class>
</hibernate-mapping>


And you start using your hibernate class.
Example to create a new entry in the database:
      try {
        Bug bug = new Bug();
        bug.setTitle("Title");
        bug.setTuserFk(tuser);
            Transaction tx = session.beginTransaction();
        session.save(bug);
        tx.commit();
      } catch (HibernateException e) {
        e.printStackTrace();
      }


The creation of the description file can be done with tools like MyEclipse. MyEclipse provides
functionality to create classes and description files directly from database tables.
Hibernate includes tools to
•   generate Java classes from description files
•   description files from existing database tables
•   database tables from description files.
Development speed is very high using hibernate.
That' s all.

More Related Content

What's hot

Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Ram132
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
hr1383
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
sourabh aggarwal
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
John Slick
 

What's hot (20)

Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Jpa 2.1 Application Development
Jpa 2.1 Application DevelopmentJpa 2.1 Application Development
Jpa 2.1 Application Development
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
Spring Data in 10 minutes
Spring Data in 10 minutesSpring Data in 10 minutes
Spring Data in 10 minutes
 
JPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsJPA 2.1 performance tuning tips
JPA 2.1 performance tuning tips
 
Hibernate
HibernateHibernate
Hibernate
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Introduction to Datastore
Introduction to DatastoreIntroduction to Datastore
Introduction to Datastore
 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Introduction To Hibernate
Introduction To HibernateIntroduction To Hibernate
Introduction To Hibernate
 
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...To Study The Tips Tricks  Guidelines Related To Performance Tuning For  N Hib...
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 
White Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application ArchitectureWhite Paper On ConCurrency For PCMS Application Architecture
White Paper On ConCurrency For PCMS Application Architecture
 
OR Mapping- nhibernate Presentation
OR Mapping- nhibernate PresentationOR Mapping- nhibernate Presentation
OR Mapping- nhibernate Presentation
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
 
JPA Best Practices
JPA Best PracticesJPA Best Practices
JPA Best Practices
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
 

Similar to Hibernate Tutorial

Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jj
Joe Jacob
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 
Patni Hibernate
Patni   HibernatePatni   Hibernate
Patni Hibernate
patinijava
 
hibernate-presentation-1196607644547952-4.pdf
hibernate-presentation-1196607644547952-4.pdfhibernate-presentation-1196607644547952-4.pdf
hibernate-presentation-1196607644547952-4.pdf
Mytrux1
 

Similar to Hibernate Tutorial (20)

Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jj
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
backend
backendbackend
backend
 
backend
backendbackend
backend
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android Application
 
5-Hibernate.ppt
5-Hibernate.ppt5-Hibernate.ppt
5-Hibernate.ppt
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaHibernate Interview Questions | Edureka
Hibernate Interview Questions | Edureka
 
Patni Hibernate
Patni   HibernatePatni   Hibernate
Patni Hibernate
 
Hibernate
HibernateHibernate
Hibernate
 
hibernate-presentation-1196607644547952-4.pdf
hibernate-presentation-1196607644547952-4.pdfhibernate-presentation-1196607644547952-4.pdf
hibernate-presentation-1196607644547952-4.pdf
 
Java Unit Testing with Unitils
Java Unit Testing with UnitilsJava Unit Testing with Unitils
Java Unit Testing with Unitils
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
Local Storage
Local StorageLocal Storage
Local Storage
 
Hibernate
HibernateHibernate
Hibernate
 

More from Syed Shahul (14)

Beginning java and flex migrating java, spring, hibernate, and maven develop...
Beginning java and flex  migrating java, spring, hibernate, and maven develop...Beginning java and flex  migrating java, spring, hibernate, and maven develop...
Beginning java and flex migrating java, spring, hibernate, and maven develop...
 
Struts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks TogetherStruts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks Together
 
Manning Struts 2 In Action
Manning Struts 2 In ActionManning Struts 2 In Action
Manning Struts 2 In Action
 
Sahih Bukhari - Tamil
Sahih Bukhari - TamilSahih Bukhari - Tamil
Sahih Bukhari - Tamil
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
Struts Live
Struts LiveStruts Live
Struts Live
 
Struts Intro
Struts IntroStruts Intro
Struts Intro
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
 
Hibernate Reference
Hibernate ReferenceHibernate Reference
Hibernate Reference
 
Spring Live Sample Chapter
Spring Live Sample ChapterSpring Live Sample Chapter
Spring Live Sample Chapter
 
Spring Reference
Spring ReferenceSpring Reference
Spring Reference
 
Jamon 22
Jamon 22Jamon 22
Jamon 22
 
Do U Know Him
Do U Know HimDo U Know Him
Do U Know Him
 
Hot Chocolate
Hot ChocolateHot Chocolate
Hot Chocolate
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Hibernate Tutorial

  • 1. What is Hibernate? This tutorial explains what Hibernate is and will show some examples why it is useful to use Hibernate. Generals Author: Sebastian Hennebrueder http://www.laliluna.de/tutorials.html Tutorials for Struts, EJB, xdoclet, JSF, JSP and eclipse. Date: February, 25th 2005 PDF Version des Tutorials: http://www.laliluna.de/assets/tutorials/what-is-hibernate-tutorial-en.pdf Main features Hibernate is a solution for object relational mapping and a persistence management solution or persistent layer. This is probably not understandable for anybody learning Hibernate. What you can imagine is probably that you have your application with some functions (business logic) and you want to save data in a database. When you use Java all the business logic normally works with objects of different class types. Your database tables are not at all objects. Hibernate provides a solution to map database tables to a class. It copies the database data to a class. In the other direction it supports to save objects to the database. In this process the object is transformed to one or more tables. Saving data to a storage is called persistence. And the copying of tables to objects and vice versa is called object relational mapping. Why using Object Relational Mapping? Better system architecture When you include all functionality of your application and the access to the database within your dialogs, you will have some severe disadvantages. It is really difficult to reuse code. You will repeat code at many places. If you change anything it is quite hard to find out all places where you have to add changes. When you separate your dialogs from your logic and the logic from the persistence mechanism you can more easily apply changes to one part without influencing the other parts. Reduce time for standard DB actions Most queries in database development are simple “insert, update, delete” statements. There is no need to develop all these tedious statements. Hibernate helps you save time.
  • 2. Loading classes from the database looks like Query query = session.createQuery("select b from Bug as b"); for (Iterator iter = query.iterate(); iter.hasNext();) { bugs.add((Bug) iter.next()); } return bugs; saving a class “bug” to the database looks like session.update(bug); Advanced features difficult to develop yourself Caching solutions, transactions and other features Hibernate provides are not so easy to implement. It is actually non sense to develop something which allready exist. Using Hibernate everything is there. You just have to use it. How Hibernate works What is nice and in my opinion an advantage over entity beans, hibernate starts from simple java classes (Pojo = Plain Old Java Objects). To use hibernate you will create a simple java class: public class Bug implements Serializable { private int hashValue = 0; private java.lang.Integer id; private java.lang.String title; public Bug() { } public Bug(java.lang.Integer fid) { this.setId(fid); } public java.lang.Integer getId() { return id; } public void setId(java.lang.Integer id) { this.id = id; } public java.lang.String getTitle() { return title; } public void setTitle(java.lang.String title) { this.title = title; } ............. Than you create a mapping file. The mapping file explains Hibernate which field in the class is mapped to which field in the database. <hibernate-mapping package="de.laliluna.fehlerbehebung"> <class name="Bug" table="bug"> <id name="id" column="fid" type="java.lang.Integer"> <generator class="sequence"> <param name="sequence">public.bug_fid_seq</param> </generator> </id> <property name="title" column="ftitle" type="java.lang.String" />
  • 3. </class> </hibernate-mapping> And you start using your hibernate class. Example to create a new entry in the database: try { Bug bug = new Bug(); bug.setTitle("Title"); bug.setTuserFk(tuser); Transaction tx = session.beginTransaction(); session.save(bug); tx.commit(); } catch (HibernateException e) { e.printStackTrace(); } The creation of the description file can be done with tools like MyEclipse. MyEclipse provides functionality to create classes and description files directly from database tables. Hibernate includes tools to • generate Java classes from description files • description files from existing database tables • database tables from description files. Development speed is very high using hibernate. That' s all.