SlideShare a Scribd company logo
By Harshit Rastogi
It is ORM (Object –Relation Mapping) Tool It uses POJO objects (Plain Old Java Objects) No direct interaction with the database.
SessionFactory – Is a factory which provides Session. Session – Single unit of work. Dirty checking Hibernate xml file – ‘.hbm’ It uses reflection
.  A typical POJO class
Event.hbm.xml <hibernate-mapping> <class name=&quot;events.Event&quot; table=&quot;EVENTS&quot;> <id name=&quot;id&quot; column=&quot;EVENT_ID&quot;> <generator class=&quot;native&quot;/> </id> <property name=“name&quot;/> <property name=&quot;address&quot; column=&quot;ADDRESS&quot;/> </class> </hibernate-mapping>
hibenrate.hbm.xml
Singleton class to create SessionFactory object
 
Get() - Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.  Load() - Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists Flush() - Force this session to flush  Delete() - Remove a persistent instance from the datastore.  Contains() -  Check if this instance is associated with this Session.  Persist() -Make a transient instance persistent.  Evict() - Remove this instance from the session cache() beginTransaction() closeTransaction()
Execute complex queries containing conditions where clauses. Criteria Interface is the option. Some typical SQL example: Select * from cat where name like “Fritz%” and weight between + minweight + and + maxweight Equivalent hibernate query: List cats = sess.createCriteria(Cat.class) .add( Restrictions.like(&quot;name&quot;, &quot;Fritz%&quot;) ) .add( Restrictions.between(&quot;weight&quot;, minWeight, maxWeight) ) .list();
List cats = sess.createCriteria(Cat.class)  .add( Restrictions.like(&quot;name&quot;, &quot;Fritz%&quot;) )  .add( Restrictions.or( Restrictions.eq( &quot;age&quot;, new Integer(0) ), Restrictions.isNull(&quot;age&quot;) ) ) .list();  List cats = sess.createCriteria(Cat.class)  .add( Restrictions.in( &quot;name&quot;, new String[] { &quot;Fritz&quot;, &quot;Izi&quot;, &quot;Pk&quot; } ) ) .add( Restrictions.disjunction() .add( Restrictions.isNull(&quot;age&quot;) ) .add( Restrictions.eq(&quot;age&quot;, new Integer(0) ) ) .add( Restrictions.eq(&quot;age&quot;, new Integer(1) ) ) .add( Restrictions.eq(&quot;age&quot;, new Integer(2) ) ) ) ) .list();
table per class hierarchy  table per subclass  table per concrete class
Exactly one table is required
Each class has its own table with the primary key related to the main class. Four tables are involved.
Each table defines columns for all properties of the class, including inherited properties.  Three tables are involved for the subclasses
Four ways of achieving mapping the in RDBMS. One-to-one One-to-many Many-to-one Many-to-many Association can be unidirectional or bi-directional.
One person can have only one address Table schema create table Person ( personId bigint not null primary key, addressId bigint not null unique ) create table Address ( addressId bigint not null primary key )
Many people sharing the same address Table Schema create table Person ( personId bigint not null primary key, addressId bigint not null ) create table Address ( addressId bigint not null primary key )
One person having many places to stay. Table Schema  create table Person ( personId bigint not null primary key ) create table Address ( addressId bigint not null primary key, personId bigint not null )
Caching can be done at various level. First level caching is done by session Second level can be done using cache frameworks Hibernate supports various implementation EHCache OSCache   SwarmCache   JBoss TreeCache

More Related Content

What's hot (20)

PDF
JPA and Hibernate
elliando dias
 
PPTX
Database change management with Liquibase
Jarosław Szczepankiewicz
 
PPTX
Liquibase
Sergii Fesenko
 
PDF
Java 8 Default Methods
Haim Michael
 
PPTX
Spring data jpa
Jeevesh Pandey
 
PPTX
JDBC - JPA - Spring Data
Arturs Drozdovs
 
PPTX
Redux workshop
Imran Sayed
 
PDF
Nouveautés Java 9-10-11
Mahamadou TOURE, Ph.D.
 
PDF
Http4s, Doobie and Circe: The Functional Web Stack
GaryCoady
 
PDF
Hibernate Presentation
guest11106b
 
PDF
Spring Data JPA
Cheng Ta Yeh
 
PDF
Spring boot jpa
Hamid Ghorbani
 
PDF
Introduction to Java 11
Knoldus Inc.
 
PPTX
REST API
Tofazzal Ahmed
 
PPT
JDBC Java Database Connectivity
Ranjan Kumar
 
PDF
Support Java Avancé Troisième Partie
ENSET, Université Hassan II Casablanca
 
PPTX
Object oreinted php | OOPs
Ravi Bhadauria
 
PDF
GraalVM: Run Programs Faster Everywhere
J On The Beach
 
PDF
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
joaomatosf_
 
PDF
Redux Toolkit - Quick Intro - 2022
Fabio Biondi
 
JPA and Hibernate
elliando dias
 
Database change management with Liquibase
Jarosław Szczepankiewicz
 
Liquibase
Sergii Fesenko
 
Java 8 Default Methods
Haim Michael
 
Spring data jpa
Jeevesh Pandey
 
JDBC - JPA - Spring Data
Arturs Drozdovs
 
Redux workshop
Imran Sayed
 
Nouveautés Java 9-10-11
Mahamadou TOURE, Ph.D.
 
Http4s, Doobie and Circe: The Functional Web Stack
GaryCoady
 
Hibernate Presentation
guest11106b
 
Spring Data JPA
Cheng Ta Yeh
 
Spring boot jpa
Hamid Ghorbani
 
Introduction to Java 11
Knoldus Inc.
 
REST API
Tofazzal Ahmed
 
JDBC Java Database Connectivity
Ranjan Kumar
 
Support Java Avancé Troisième Partie
ENSET, Université Hassan II Casablanca
 
Object oreinted php | OOPs
Ravi Bhadauria
 
GraalVM: Run Programs Faster Everywhere
J On The Beach
 
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
joaomatosf_
 
Redux Toolkit - Quick Intro - 2022
Fabio Biondi
 

Viewers also liked (20)

PPT
Intro To Hibernate
Amit Himani
 
PPS
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
PPT
Hibernate Tutorial
Ram132
 
DOC
Hibernate tutorial for beginners
Rahul Jain
 
PDF
Hibernate ORM: Tips, Tricks, and Performance Techniques
Brett Meyer
 
PPT
Java Persistence API (JPA) Step By Step
Guo Albert
 
PDF
Hibernate An Introduction
Nguyen Cao
 
PPT
Hibernation PPT Lesson 9
drlech123
 
PPT
Hibernate presentation
Manav Prasad
 
PPTX
Hibernate
Prashant Kalkar
 
ODP
ORM, JPA, & Hibernate Overview
Brett Meyer
 
PPT
Java Servlets
BG Java EE Course
 
ODP
Hibernate Developer Reference
Muthuselvam RS
 
PPSX
JDBC: java DataBase connectivity
Tanmoy Barman
 
PPT
Java Servlets
Nitin Pai
 
PPT
Hibernate Session 4
b_kathir
 
PPT
Animals Winter
hiratufail
 
PPTX
Who Hibernates
molliekay
 
Intro To Hibernate
Amit Himani
 
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
Hibernate Tutorial
Ram132
 
Hibernate tutorial for beginners
Rahul Jain
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Brett Meyer
 
Java Persistence API (JPA) Step By Step
Guo Albert
 
Hibernate An Introduction
Nguyen Cao
 
Hibernation PPT Lesson 9
drlech123
 
Hibernate presentation
Manav Prasad
 
Hibernate
Prashant Kalkar
 
ORM, JPA, & Hibernate Overview
Brett Meyer
 
Java Servlets
BG Java EE Course
 
Hibernate Developer Reference
Muthuselvam RS
 
JDBC: java DataBase connectivity
Tanmoy Barman
 
Java Servlets
Nitin Pai
 
Hibernate Session 4
b_kathir
 
Animals Winter
hiratufail
 
Who Hibernates
molliekay
 
Ad

Similar to Introduction to hibernate (20)

PDF
Hibernate Reference
Syed Shahul
 
PPT
Introduction to hibernate
Muhammad Zeeshan
 
PPT
Hibernate training
TechFerry
 
DOC
Hibernate Online Training
Srihitha Technologies
 
PPT
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Baruch Sadogursky
 
PDF
Hibernate Reference
Saverio Menin
 
PPT
04 Data Access
Ranjan Kumar
 
PDF
ActiveJDBC - ActiveRecord implementation in Java
ipolevoy
 
PPT
08 Queries
Ranjan Kumar
 
PPT
Advanced Hibernate
Haitham Raik
 
PDF
Hibernate reference
Arvind Moorthy
 
PDF
Using Scala Slick at FortyTwo
Eishay Smith
 
PDF
Kick Start Jpa
Stephan Janssen
 
PPT
5-Hibernate.ppt
ShivaPriya60
 
PDF
Hibernate Mapping
InnovationM
 
PDF
Hibernate Mapping
InnovationM
 
PPTX
JPA 2.0
Emiel Paasschens
 
ODP
Using DAOs without implementing them
benfante
 
PPT
hibernate with JPA
Mohammad Faizan
 
Hibernate Reference
Syed Shahul
 
Introduction to hibernate
Muhammad Zeeshan
 
Hibernate training
TechFerry
 
Hibernate Online Training
Srihitha Technologies
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Baruch Sadogursky
 
Hibernate Reference
Saverio Menin
 
04 Data Access
Ranjan Kumar
 
ActiveJDBC - ActiveRecord implementation in Java
ipolevoy
 
08 Queries
Ranjan Kumar
 
Advanced Hibernate
Haitham Raik
 
Hibernate reference
Arvind Moorthy
 
Using Scala Slick at FortyTwo
Eishay Smith
 
Kick Start Jpa
Stephan Janssen
 
5-Hibernate.ppt
ShivaPriya60
 
Hibernate Mapping
InnovationM
 
Hibernate Mapping
InnovationM
 
Using DAOs without implementing them
benfante
 
hibernate with JPA
Mohammad Faizan
 
Ad

Recently uploaded (20)

PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Designing Production-Ready AI Agents
Kunal Rai
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Designing Production-Ready AI Agents
Kunal Rai
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Biography of Daniel Podor.pdf
Daniel Podor
 

Introduction to hibernate

  • 2. It is ORM (Object –Relation Mapping) Tool It uses POJO objects (Plain Old Java Objects) No direct interaction with the database.
  • 3. SessionFactory – Is a factory which provides Session. Session – Single unit of work. Dirty checking Hibernate xml file – ‘.hbm’ It uses reflection
  • 4. . A typical POJO class
  • 5. Event.hbm.xml <hibernate-mapping> <class name=&quot;events.Event&quot; table=&quot;EVENTS&quot;> <id name=&quot;id&quot; column=&quot;EVENT_ID&quot;> <generator class=&quot;native&quot;/> </id> <property name=“name&quot;/> <property name=&quot;address&quot; column=&quot;ADDRESS&quot;/> </class> </hibernate-mapping>
  • 7. Singleton class to create SessionFactory object
  • 8.  
  • 9. Get() - Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. Load() - Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists Flush() - Force this session to flush Delete() - Remove a persistent instance from the datastore. Contains() -  Check if this instance is associated with this Session. Persist() -Make a transient instance persistent. Evict() - Remove this instance from the session cache() beginTransaction() closeTransaction()
  • 10. Execute complex queries containing conditions where clauses. Criteria Interface is the option. Some typical SQL example: Select * from cat where name like “Fritz%” and weight between + minweight + and + maxweight Equivalent hibernate query: List cats = sess.createCriteria(Cat.class) .add( Restrictions.like(&quot;name&quot;, &quot;Fritz%&quot;) ) .add( Restrictions.between(&quot;weight&quot;, minWeight, maxWeight) ) .list();
  • 11. List cats = sess.createCriteria(Cat.class) .add( Restrictions.like(&quot;name&quot;, &quot;Fritz%&quot;) ) .add( Restrictions.or( Restrictions.eq( &quot;age&quot;, new Integer(0) ), Restrictions.isNull(&quot;age&quot;) ) ) .list(); List cats = sess.createCriteria(Cat.class) .add( Restrictions.in( &quot;name&quot;, new String[] { &quot;Fritz&quot;, &quot;Izi&quot;, &quot;Pk&quot; } ) ) .add( Restrictions.disjunction() .add( Restrictions.isNull(&quot;age&quot;) ) .add( Restrictions.eq(&quot;age&quot;, new Integer(0) ) ) .add( Restrictions.eq(&quot;age&quot;, new Integer(1) ) ) .add( Restrictions.eq(&quot;age&quot;, new Integer(2) ) ) ) ) .list();
  • 12. table per class hierarchy table per subclass table per concrete class
  • 13. Exactly one table is required
  • 14. Each class has its own table with the primary key related to the main class. Four tables are involved.
  • 15. Each table defines columns for all properties of the class, including inherited properties. Three tables are involved for the subclasses
  • 16. Four ways of achieving mapping the in RDBMS. One-to-one One-to-many Many-to-one Many-to-many Association can be unidirectional or bi-directional.
  • 17. One person can have only one address Table schema create table Person ( personId bigint not null primary key, addressId bigint not null unique ) create table Address ( addressId bigint not null primary key )
  • 18. Many people sharing the same address Table Schema create table Person ( personId bigint not null primary key, addressId bigint not null ) create table Address ( addressId bigint not null primary key )
  • 19. One person having many places to stay. Table Schema create table Person ( personId bigint not null primary key ) create table Address ( addressId bigint not null primary key, personId bigint not null )
  • 20. Caching can be done at various level. First level caching is done by session Second level can be done using cache frameworks Hibernate supports various implementation EHCache OSCache SwarmCache JBoss TreeCache