SlideShare a Scribd company logo
Introduction to Hibernate
Agenda Introduction to Hibernate Hibernate Architecture Persistence Lifecycle Object Identity Mapping tables to beans Mapping properties to columns Relationships Setting up a one to many relationships Setting up a many to many relationships Hibernate Transaction API Basic Queries Working with Queries Named Queries working with the query API Working with binding parameters
Plain JDBC Simple example to insert a row into database table, using JDBC public void insertRow(Employee emp) { String insertSQL = “INSERT INTO emp values(….); Connection conn = getConnectionFromPool(); Statement stmt = conn.createStatement(insertSQL); stmt.execute(); }
Hibernate Persistence for JavaBean/POJO Support for fine-grained, richly typed object models Powerful queries Support for detached persistence objects Mapping meta data in XML file
Hibernate Configuration The hibernate.properties file Used for hibernate configuration Contains Database configuration Datasource configuration Transaction configuration Caching configuration Connection pool configuration Other settings
Hibernate Configuration... Contd The hibernate.cfg.xml Alternative approach of configuration Can be used as replacement of hibernate.properties Picked up from classpath Has got precedence on hibernate.properties file
Hibernate Configuration... Contd Non managed environment <hibernate-configuration> <session-factory> <property name=&quot;hibernate.connection.driver_class&quot;>    COM.ibm.db2.jdbc.app.DB2Driver </property> <property name=&quot;hibernate.connection.url&quot;>jdbc:db2:SAMPLE</property> <property name=&quot;hibernate.connection.username&quot;>db2admin</property> <property name=&quot;hibernate.connection.password&quot;>db2admin</property> <property name=&quot;hibernate.connection.pool_size&quot;>10</property> <property name=&quot;show_sql&quot;>true</property> <property name=&quot;dialect&quot;>net.sf.hibernate.dialect.DB2Dialect</property> <!-- Mapping files --> <mapping resource=&quot;test_emp.hbm.xml&quot;/> </session-factory> </hibernate-configuration>
Hibernate Configuration... Contd Managed environment (App Server) <hibernate-configuration> <session-factory> <property name=&quot;hibernate.connection.datasource&quot;> java:comp/env/jdbc/my_ds1 </property> <property name=&quot;hibernate.transaction.factory_class&quot;> org.hibernate.transaction.CMTTransactionFactory </property> <property name=&quot;hibernate.transaction.manager_lookup_class&quot;> org.hibernate.transaction.WebSphereExtendedJTATransactionLookup </property>   <property name=&quot;show_sql&quot;>true</property>   <property name=&quot;dialect&quot;>org.hibernate.dialect.DB2Dialect</property> <mapping resource=&quot;emp.hbm.xml&quot;/> <mapping resource=&quot;dept.hbm.xml&quot;/> </session-factory> </hibernate-configuration>
Hibernate Mapping The hibernate-mapping xml file <hibernate-mapping> <class name=&quot;com.entity.Emp&quot; table=&quot;EMP&quot;> <id name=&quot;empId&quot; column=&quot;EMP_ID&quot; > <generator class=&quot;native&quot;></generator> </id> <property name=&quot;empName&quot; column=&quot;EMP_NAME&quot;></property> <property name=&quot;city&quot; column=&quot;CITY&quot;></property> <property name=&quot;deptId&quot; column=&quot;DEPT_ID&quot;></property> <property name=&quot;joinDate&quot; column=&quot;JOIN_DATE&quot;></property> <property name=“gender&quot; column=“GENDER&quot;></property> </class> </hibernate-mapping>
Simple standalone hibernate appliation Requirements Hibernate libraries Hibernate configuration file A POJO class A hibernate-mapping file A Main class
Sample POJO public class Emp implements SplEntity { private Integer empId; private String empName; private String city; private int deptId; private Date joinDate; private char gender; public String getCity() { return city; } public void setCity(String city) { this.city = city; } public int getDeptId() { return deptId; } public void setDeptId(int deptId) { this.deptId = deptId; } public Integer getEmpId() { return empId; } public void setEmpId(Integer empId) { this.empId = empId; } public String getEmpName() { return empName; } public void setEmpName(String empName) { this.empName = empName; } public Date getJoinDate() { return joinDate; } public void setJoinDate(Date joinDate) { this.joinDate = joinDate; } public char getGender() { return gender; } public void setGender(char gender) { this.gender = gender; } }
Sample Main class Public class Main { public static void main(String[] args) {   try {   SessionFactory factory = null;   factory = new Configuration().configure().buildSessionFactory(); Session session = factory.openSession(); Transaction tx = session.beginTransaction(); Emp e1 = new Emp(); e1.setEmpName(“Rajesh B&quot;); e1.setCity(“Pune&quot;); e1.setDeptId(3); e1.setJoinDate(new Date(&quot;20-Jul-1995&quot;)); session.save(e1); tx.commit();   } catch (Exception e) { e.printStackTrace();   } } }
Hibernate Architecture
High Level View
Understanding the Architecture
Hibernate core interfaces Session SessionFactory Configuration Transaction  Query Criteria Types
Session Interface
SessionFactory Interface
Configuration Interface
Transaction Interface
Query and Criteria Interfaces
Configuring logging in Hibernate
Basic O/R Mapping
Hibernate-Mapping
Class Element
ID element
Composite ID Element
Built in Types
Mapping Collections
Persistent Collections
Emp model table relationship
Mapping Set
Lazy Initialization
Component Mapping
Dependent Object
Sample table definition
Employee-Address data model
Example of component mapping
Address class
Mapping Component
Mapping Associations
Associations
Many to one association <class name=&quot;com.entity.Emp&quot; table=&quot;EMP&quot;> ... ... <many-to-one name=&quot;dept&quot;   column=&quot;DEPT_ID&quot;   class=&quot;Department&quot;   not-null=&quot;true&quot; /> </class>
Parent child relationship <class name=&quot;com.entity.Dept&quot; table=&quot;DEPT&quot;> ... ... <set name=&quot;employees&quot;   inverse=&quot;true&quot;   cascade=&quot;all-delete-orphan&quot;>     <key column=&quot;DEPT_ID&quot; />   <one-to-many class=&quot;Emp&quot; /> </set> </class>
One to one relationship Employee-Person Object Dig
One to one association <class name=&quot;com.entity.Emp&quot; table=&quot;EMP&quot;> ... ... <one-to-one name=&quot;person&quot; class=&quot;Person&quot; /> </class>
Many to many relationship
Link table structure EMP_TASKS table
Many to many association
Manipulating Persistence Data
Persistence Lifecycle
Transient Objects
Persistent Objects
Detached Objects
Persistence Manager
Making an object persistent
Retrieving persistent object
Updating persistent object
Committing a database transaction
Transaction and Concurrency
Understanding database transactions
Hibernate Transaction API
JDBC Transactions
2 Phase Transactions
Hibernate Query Language HQL
Introduction to HQL
Query Interface
Binding Parameters
An example of simple Query
HQL supports: WHERE clause ORDER BY clause GROUP BY clause All types of joins (inner, left outer, right outer, outer) Subquery etc
Reporting Queries
Criteria Queries
Simple Criteria example
Other query types supported Query By Example Native SLQ query
Cache
Mass Update/Deletes
Hibernate Cache Architecture
Hibernate First Level Cache
Hibernate Second Level Cache
Caching Strategies
Enabling Caching
Any Questions ?
Thanks !!!

More Related Content

What's hot (20)

PDF
Hibernate An Introduction
Nguyen Cao
 
PPTX
Hibernate
Prashant Kalkar
 
PPTX
Hibernate working with criteria- Basic Introduction
Er. Gaurav Kumar
 
PPT
jpa-hibernate-presentation
John Slick
 
ODP
JavaEE Spring Seam
Carol McDonald
 
PPTX
Hibernate inheritance and relational mappings with examples
Er. Gaurav Kumar
 
PPT
ORM Concepts and JPA 2.0 Specifications
Ahmed Ramzy
 
PDF
Hibernate using jpa
Mohammad Faizan
 
PPTX
Hibernate Basic Concepts - Presentation
Khoa Nguyen
 
PPTX
Spring (1)
Aneega
 
PPTX
Hibernate ppt
Aneega
 
PPTX
Hibernate in Action
Akshay Ballarpure
 
PPTX
Introduction to JPA (JPA version 2.0)
ejlp12
 
PDF
JSP Standard Tag Library
Ilio Catallo
 
PPT
Entity Persistence with JPA
Subin Sugunan
 
PPTX
Introduction to JPA Framework
Collaboration Technologies
 
ODP
Hibernate complete Training
sourabh aggarwal
 
PDF
Java persistence api 2.1
Rakesh K. Cherukuri
 
ODP
2008.07.17 발표
Sunjoo Park
 
PPTX
Spring data jpa
Jeevesh Pandey
 
Hibernate An Introduction
Nguyen Cao
 
Hibernate
Prashant Kalkar
 
Hibernate working with criteria- Basic Introduction
Er. Gaurav Kumar
 
jpa-hibernate-presentation
John Slick
 
JavaEE Spring Seam
Carol McDonald
 
Hibernate inheritance and relational mappings with examples
Er. Gaurav Kumar
 
ORM Concepts and JPA 2.0 Specifications
Ahmed Ramzy
 
Hibernate using jpa
Mohammad Faizan
 
Hibernate Basic Concepts - Presentation
Khoa Nguyen
 
Spring (1)
Aneega
 
Hibernate ppt
Aneega
 
Hibernate in Action
Akshay Ballarpure
 
Introduction to JPA (JPA version 2.0)
ejlp12
 
JSP Standard Tag Library
Ilio Catallo
 
Entity Persistence with JPA
Subin Sugunan
 
Introduction to JPA Framework
Collaboration Technologies
 
Hibernate complete Training
sourabh aggarwal
 
Java persistence api 2.1
Rakesh K. Cherukuri
 
2008.07.17 발표
Sunjoo Park
 
Spring data jpa
Jeevesh Pandey
 

Viewers also liked (20)

PDF
Hibernate Presentation
guest11106b
 
PPS
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
DOC
Hibernate tutorial for beginners
Rahul Jain
 
ODP
Hibernate Developer Reference
Muthuselvam RS
 
PDF
Hibernate ORM: Tips, Tricks, and Performance Techniques
Brett Meyer
 
ODP
ORM, JPA, & Hibernate Overview
Brett Meyer
 
PPT
Hibernate
Ajay K
 
PPT
Hibernation PPT Lesson 9
drlech123
 
PPT
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
PPT
Java Persistence API (JPA) Step By Step
Guo Albert
 
PPT
Java Servlets
BG Java EE Course
 
PPSX
JDBC: java DataBase connectivity
Tanmoy Barman
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
PPT
Java Servlets
Nitin Pai
 
PPT
Introduction to Hibernate
Krishnakanth Goud
 
PPTX
JavaEdge09 : Java Indexing and Searching
Shay Sofer
 
PPT
Contemporary Software Engineering Practices Together With Enterprise
Kenan Sevindik
 
PDF
Developing Reusable Software Components Using MVP, Observer and Mediator Patt...
Kenan Sevindik
 
PDF
Document retrieval using clustering
eSAT Journals
 
Hibernate Presentation
guest11106b
 
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
Hibernate tutorial for beginners
Rahul Jain
 
Hibernate Developer Reference
Muthuselvam RS
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Brett Meyer
 
ORM, JPA, & Hibernate Overview
Brett Meyer
 
Hibernate
Ajay K
 
Hibernation PPT Lesson 9
drlech123
 
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
Java Persistence API (JPA) Step By Step
Guo Albert
 
Java Servlets
BG Java EE Course
 
JDBC: java DataBase connectivity
Tanmoy Barman
 
Spring Framework - Core
Dzmitry Naskou
 
Java Servlets
Nitin Pai
 
Introduction to Hibernate
Krishnakanth Goud
 
JavaEdge09 : Java Indexing and Searching
Shay Sofer
 
Contemporary Software Engineering Practices Together With Enterprise
Kenan Sevindik
 
Developing Reusable Software Components Using MVP, Observer and Mediator Patt...
Kenan Sevindik
 
Document retrieval using clustering
eSAT Journals
 
Ad

Similar to Intro To Hibernate (20)

PPT
Basic Hibernate Final
Rafael Coutinho
 
DOCX
4.3 Hibernate example.docx
yasothamohankumar
 
PPT
Patni Hibernate
patinijava
 
PPTX
Hibernate example1
myrajendra
 
PPT
5-Hibernate.ppt
ShivaPriya60
 
PPT
Download It
webhostingguy
 
PPTX
Introduction to Hibernate Framework
Collaboration Technologies
 
PPTX
Hibernate online training
QUONTRASOLUTIONS
 
PPTX
New-Hibernate-introduction cloud cc.pptx
bgvthm
 
PPT
Introduction to hibernate
Muhammad Zeeshan
 
PPT
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Baruch Sadogursky
 
PPTX
Hibernate Training Session1
Asad Khan
 
PPTX
Session 3 - hibernate - Configuration with Annotations.pptx
ASRPANDEY
 
PPTX
Hibernate in XPages
Toby Samples
 
PPT
Hibernate
Murali Pachiyappan
 
ODP
Hibernate 18052012
Manisha Balwadkar
 
PPT
Hibernate training
TechFerry
 
PDF
Hibernate Mapping
InnovationM
 
PDF
Hibernate Mapping
InnovationM
 
PDF
Hibernate notesforprofessionals
Right
 
Basic Hibernate Final
Rafael Coutinho
 
4.3 Hibernate example.docx
yasothamohankumar
 
Patni Hibernate
patinijava
 
Hibernate example1
myrajendra
 
5-Hibernate.ppt
ShivaPriya60
 
Download It
webhostingguy
 
Introduction to Hibernate Framework
Collaboration Technologies
 
Hibernate online training
QUONTRASOLUTIONS
 
New-Hibernate-introduction cloud cc.pptx
bgvthm
 
Introduction to hibernate
Muhammad Zeeshan
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Baruch Sadogursky
 
Hibernate Training Session1
Asad Khan
 
Session 3 - hibernate - Configuration with Annotations.pptx
ASRPANDEY
 
Hibernate in XPages
Toby Samples
 
Hibernate 18052012
Manisha Balwadkar
 
Hibernate training
TechFerry
 
Hibernate Mapping
InnovationM
 
Hibernate Mapping
InnovationM
 
Hibernate notesforprofessionals
Right
 
Ad

Recently uploaded (20)

PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 

Intro To Hibernate