SlideShare a Scribd company logo
Hibernate
Content covered
• Introduction to Hibernate
• Hibernate Architecture
• O/R Mapping in Hibernate
Hibernate Architecture
Configuration
(org.hibernate.cfg.Configuration)
• The Configuration object, as seen in the
example code, is the first Hibernate object you
use. It represents a configuration or properties
file for Hibernate. The Configuration object is
usually created once during application
initialization.
• The Configuration object reads and establishes
the properties Hibernate uses to get connected
to a database and configure itself for work. A
Configuration object is used to create a
SessionFactory and then typically is discarded.
Example
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class"> org.hsqldb.jdbcDriver
</property>
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost
</property>
<property name="hibernate.connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect"> org.hibernate.dialect.HSQLDialect
</property>
<mapping resource="com/vaannila/student/Student.hbm.xml"/>
<mapping resource="com/vaannila/student/Address.hbm.xml"/>
</session-factory>
</hibernate-configuration>
SessionFactory
(org.hibernate.SessionFactory)
• Created from a Configuration object, and
as its name implies it is a factory for
Session objects.
• An expensive object to create. It, like the
Configuration object, is usually created
during application start up. However,
unlike the Configuration object, It should
be created once and kept for later use.
SessionFactory
• SessionFactory object,
– used by all the threads of an application. It is
a thread safe object.
– One SessionFactory object is created per
database.
– Multiple SessionFactory objects (each
requiring a separate Configuration) are
created when connecting to multiple
databases.
Hibernate Flow of Work
Session
(org.hibernate.Session)
• Provide the main interface to accomplish work with the
database. Persistent objects are saved
and retrieved through a Session object.
• Lightweight & inexpensive to create, does the work of
getting a physical connection to the database.
• Not thread safe. Therefore, session objects should not
be kept open for a long time.
• Applications create and destroy these as needed.
• When modifications are made to the database, Session
objects create a Transaction object.
Transaction
(org.hibernate.Transaction)
• Represents a unit of work with the database
(and potentially other systems). Transactions in
Hibernate are handled by an underlying
transaction manager and transaction (from
JDBC, JTA or CORBA).
• Abstracts the developer from having to deal with
the underlying transaction manager/transaction.
• Transaction objects should be kept open for as
short of time as
possible.
Example
Sessionsession=
SessionFactory.newSession();
Transaction tx = session.beginTransaction( );
tx.commit(); tx.rollback();
session.close()
Query & Criteria
• Both objects are used to retrieve (and
recreate) persistent objects.
• Query objects use SQL or Hibernate
Query Language (HQL) string to retrieve
data from the database & create objects.
• Criteria enables developer to create and
execute the object-oriented criteria
queries.
Hibernate O/R Mapping
• ORM is a technique to map object-
oriented data with the relational data.
• Used to convert datatype supported in
object-oriented programming language to
a datatype to a data type supported by a
database. (if mapping is not provided,
exception is thrown while transferring an
object oriented data to the database)
Hibernate O/R Mapping
• Mapping in the format that relate
– Classes with tables.
– Properties with columns
– SQL types with Java types.
• O/R Mapping can be written for any
database that can be oracle, DB2, MySql,
Sybase.
Hibernate O/R Mapping
• xml file
XML mapping documents allows you to:
– Bridge the gap between object-oriented
systems and relational databases
– Define the object-relational mapping
– Help to generate and export database table
Associations strategies
• Mainly 3 Association strategies available
in O/R mapping:
• 1. One-2-one
• 2. One-2-many
• 3. Many-2-one
• 4. Many-2-many
Hibernate Mapping files
<?xml version="1.0"?>
<hibernate-mapping>
<class name="com.vaannila.student.Student" table="STUDENT">
<id name="studentId" type="long" column="STUDENT_ID">
<generator class="native“/></id>
<property name="studentName" type="string" not-null="true"
length="100" column="STUDENT_NAME" />
<many-to-one name="studentAddress"
class="com.vaannila.student.Address"
column="STUDENT_ADDRESS" not-null="true" cascade="all"
unique="true" />
</class>
</hibernate-mapping>

More Related Content

What's hot

Electron, databases, and RxDB
Electron, databases, and RxDBElectron, databases, and RxDB
Electron, databases, and RxDB
Ben Gotow
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
Raveendra R
 
Lokijs
LokijsLokijs
Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)
Igor Anishchenko
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
Samnang Chhun
 
Kantara OTTO slides
Kantara OTTO slidesKantara OTTO slides
Kantara OTTO slides
Mike Schwartz
 
DataFinder concepts and example: General (20100503)
DataFinder concepts and example: General (20100503)DataFinder concepts and example: General (20100503)
DataFinder concepts and example: General (20100503)
Data Finder
 
NHibernate
NHibernateNHibernate
NHibernate
gabrielcerutti
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
hr1383
 
ELK - Stack - Munich .net UG
ELK - Stack - Munich .net UGELK - Stack - Munich .net UG
ELK - Stack - Munich .net UG
Steve Behrendt
 
Deep dive into the native multi model database ArangoDB
Deep dive into the native multi model database ArangoDBDeep dive into the native multi model database ArangoDB
Deep dive into the native multi model database ArangoDB
ArangoDB Database
 
Configuring jpa in a Spring application
Configuring jpa in a  Spring applicationConfiguring jpa in a  Spring application
Configuring jpa in a Spring application
Jayasree Perilakkalam
 
MySQL Connector/Node.js and the X DevAPI
MySQL Connector/Node.js and the X DevAPIMySQL Connector/Node.js and the X DevAPI
MySQL Connector/Node.js and the X DevAPI
Rui Quelhas
 
Indexed db
Indexed dbIndexed db
Indexed db
Martin Giger
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overview
Amit Juneja
 
Node.js and the MySQL Document Store
Node.js and the MySQL Document StoreNode.js and the MySQL Document Store
Node.js and the MySQL Document Store
Rui Quelhas
 
IMC Summit 2016 Breakout - William Bain - Implementing Extensible Data Struct...
IMC Summit 2016 Breakout - William Bain - Implementing Extensible Data Struct...IMC Summit 2016 Breakout - William Bain - Implementing Extensible Data Struct...
IMC Summit 2016 Breakout - William Bain - Implementing Extensible Data Struct...
In-Memory Computing Summit
 
Webinar Slides: Tungsten Replicator for Elasticsearch - Real-time data loadin...
Webinar Slides: Tungsten Replicator for Elasticsearch - Real-time data loadin...Webinar Slides: Tungsten Replicator for Elasticsearch - Real-time data loadin...
Webinar Slides: Tungsten Replicator for Elasticsearch - Real-time data loadin...
Continuent
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo db
Eman Mohamed
 
Elastic Stack Introduction
Elastic Stack IntroductionElastic Stack Introduction
Elastic Stack Introduction
Vikram Shinde
 

What's hot (20)

Electron, databases, and RxDB
Electron, databases, and RxDBElectron, databases, and RxDB
Electron, databases, and RxDB
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
Lokijs
LokijsLokijs
Lokijs
 
Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
 
Kantara OTTO slides
Kantara OTTO slidesKantara OTTO slides
Kantara OTTO slides
 
DataFinder concepts and example: General (20100503)
DataFinder concepts and example: General (20100503)DataFinder concepts and example: General (20100503)
DataFinder concepts and example: General (20100503)
 
NHibernate
NHibernateNHibernate
NHibernate
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 
ELK - Stack - Munich .net UG
ELK - Stack - Munich .net UGELK - Stack - Munich .net UG
ELK - Stack - Munich .net UG
 
Deep dive into the native multi model database ArangoDB
Deep dive into the native multi model database ArangoDBDeep dive into the native multi model database ArangoDB
Deep dive into the native multi model database ArangoDB
 
Configuring jpa in a Spring application
Configuring jpa in a  Spring applicationConfiguring jpa in a  Spring application
Configuring jpa in a Spring application
 
MySQL Connector/Node.js and the X DevAPI
MySQL Connector/Node.js and the X DevAPIMySQL Connector/Node.js and the X DevAPI
MySQL Connector/Node.js and the X DevAPI
 
Indexed db
Indexed dbIndexed db
Indexed db
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overview
 
Node.js and the MySQL Document Store
Node.js and the MySQL Document StoreNode.js and the MySQL Document Store
Node.js and the MySQL Document Store
 
IMC Summit 2016 Breakout - William Bain - Implementing Extensible Data Struct...
IMC Summit 2016 Breakout - William Bain - Implementing Extensible Data Struct...IMC Summit 2016 Breakout - William Bain - Implementing Extensible Data Struct...
IMC Summit 2016 Breakout - William Bain - Implementing Extensible Data Struct...
 
Webinar Slides: Tungsten Replicator for Elasticsearch - Real-time data loadin...
Webinar Slides: Tungsten Replicator for Elasticsearch - Real-time data loadin...Webinar Slides: Tungsten Replicator for Elasticsearch - Real-time data loadin...
Webinar Slides: Tungsten Replicator for Elasticsearch - Real-time data loadin...
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo db
 
Elastic Stack Introduction
Elastic Stack IntroductionElastic Stack Introduction
Elastic Stack Introduction
 

Viewers also liked

The Magic of ATMvertising
The Magic of ATMvertisingThe Magic of ATMvertising
The Magic of ATMvertising
DenMas Wibi
 
Austin Web Architecture
Austin Web ArchitectureAustin Web Architecture
Austin Web Architecture
joaquincasares
 
Radcab
RadcabRadcab
Radcab
nblevine
 
Презентация
ПрезентацияПрезентация
Презентация
1kniga
 
This Is How I See 2012 Results To Date
This Is How I See 2012   Results To DateThis Is How I See 2012   Results To Date
This Is How I See 2012 Results To Date
Lydia Ofori
 
Prasanth1
Prasanth1Prasanth1
Prasanth1
chintakunta07
 
Happy DevOps with Apache Cassandra and DataStax
Happy DevOps with Apache Cassandra and DataStaxHappy DevOps with Apache Cassandra and DataStax
Happy DevOps with Apache Cassandra and DataStax
joaquincasares
 
ысоцкий
ысоцкийысоцкий
ысоцкий
ubnkh
 
This Is How I See 2012 Results To Date231211
This Is How I See 2012   Results To Date231211This Is How I See 2012   Results To Date231211
This Is How I See 2012 Results To Date231211
Lydia Ofori
 
HFA pMDI Patents Perspectives Gold Mine Or Minefield Ph Rogueda 12 Decemb...
HFA pMDI Patents Perspectives Gold Mine Or Minefield   Ph Rogueda   12 Decemb...HFA pMDI Patents Perspectives Gold Mine Or Minefield   Ph Rogueda   12 Decemb...
HFA pMDI Patents Perspectives Gold Mine Or Minefield Ph Rogueda 12 Decemb...
Philippe Rogueda
 
Choosing the right device: The case for nebulisers
Choosing the right device: The case for nebulisersChoosing the right device: The case for nebulisers
Choosing the right device: The case for nebulisers
Philippe Rogueda
 
Open Innovation In The Inhalation Field Academia And Industry As Partners P...
Open Innovation In The Inhalation Field Academia And Industry As Partners   P...Open Innovation In The Inhalation Field Academia And Industry As Partners   P...
Open Innovation In The Inhalation Field Academia And Industry As Partners P...
Philippe Rogueda
 
ADA APS talk 4 APS 4 April 15
ADA APS talk 4 APS 4 April 15ADA APS talk 4 APS 4 April 15
ADA APS talk 4 APS 4 April 15
Philippe Rogueda
 
Has innovation in inhalation drug delivery run out of steam?
Has innovation in inhalation drug delivery run out of steam?Has innovation in inhalation drug delivery run out of steam?
Has innovation in inhalation drug delivery run out of steam?
Philippe Rogueda
 
баскетбол
баскетболбаскетбол
баскетбол
ubnkh
 
Persyaratan umum pemukiman yang aman di daerah pesisir dan urban
Persyaratan umum pemukiman yang aman di daerah pesisir dan urbanPersyaratan umum pemukiman yang aman di daerah pesisir dan urban
Persyaratan umum pemukiman yang aman di daerah pesisir dan urbanStefan Stefan
 
Literary criticism overview
Literary criticism overviewLiterary criticism overview
Literary criticism overview
nblevine
 
высоцкий
высоцкийвысоцкий
высоцкийubnkh
 

Viewers also liked (18)

The Magic of ATMvertising
The Magic of ATMvertisingThe Magic of ATMvertising
The Magic of ATMvertising
 
Austin Web Architecture
Austin Web ArchitectureAustin Web Architecture
Austin Web Architecture
 
Radcab
RadcabRadcab
Radcab
 
Презентация
ПрезентацияПрезентация
Презентация
 
This Is How I See 2012 Results To Date
This Is How I See 2012   Results To DateThis Is How I See 2012   Results To Date
This Is How I See 2012 Results To Date
 
Prasanth1
Prasanth1Prasanth1
Prasanth1
 
Happy DevOps with Apache Cassandra and DataStax
Happy DevOps with Apache Cassandra and DataStaxHappy DevOps with Apache Cassandra and DataStax
Happy DevOps with Apache Cassandra and DataStax
 
ысоцкий
ысоцкийысоцкий
ысоцкий
 
This Is How I See 2012 Results To Date231211
This Is How I See 2012   Results To Date231211This Is How I See 2012   Results To Date231211
This Is How I See 2012 Results To Date231211
 
HFA pMDI Patents Perspectives Gold Mine Or Minefield Ph Rogueda 12 Decemb...
HFA pMDI Patents Perspectives Gold Mine Or Minefield   Ph Rogueda   12 Decemb...HFA pMDI Patents Perspectives Gold Mine Or Minefield   Ph Rogueda   12 Decemb...
HFA pMDI Patents Perspectives Gold Mine Or Minefield Ph Rogueda 12 Decemb...
 
Choosing the right device: The case for nebulisers
Choosing the right device: The case for nebulisersChoosing the right device: The case for nebulisers
Choosing the right device: The case for nebulisers
 
Open Innovation In The Inhalation Field Academia And Industry As Partners P...
Open Innovation In The Inhalation Field Academia And Industry As Partners   P...Open Innovation In The Inhalation Field Academia And Industry As Partners   P...
Open Innovation In The Inhalation Field Academia And Industry As Partners P...
 
ADA APS talk 4 APS 4 April 15
ADA APS talk 4 APS 4 April 15ADA APS talk 4 APS 4 April 15
ADA APS talk 4 APS 4 April 15
 
Has innovation in inhalation drug delivery run out of steam?
Has innovation in inhalation drug delivery run out of steam?Has innovation in inhalation drug delivery run out of steam?
Has innovation in inhalation drug delivery run out of steam?
 
баскетбол
баскетболбаскетбол
баскетбол
 
Persyaratan umum pemukiman yang aman di daerah pesisir dan urban
Persyaratan umum pemukiman yang aman di daerah pesisir dan urbanPersyaratan umum pemukiman yang aman di daerah pesisir dan urban
Persyaratan umum pemukiman yang aman di daerah pesisir dan urban
 
Literary criticism overview
Literary criticism overviewLiterary criticism overview
Literary criticism overview
 
высоцкий
высоцкийвысоцкий
высоцкий
 

Similar to Hibernate

Hibernate
HibernateHibernate
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
Mumbai Academisc
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
Akshay Ballarpure
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
kanchanmahajan23
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
Krishnakanth Goud
 
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
kamal kotecha
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
kanchanmahajan23
 
Hibernate - Part 2
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2
Hitesh-Java
 
Hibernate
HibernateHibernate
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
PawanMM
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
sourabh aggarwal
 
Hibernate
HibernateHibernate
Hibernate
Sujit Kumar
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
Rajiv Gupta
 
Hibernate training-topics
Hibernate training-topicsHibernate training-topics
Hibernate training-topics
Vibrant Technologies & Computers
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1
Hitesh-Java
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
Toby Samples
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
kanchanmahajan23
 
Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1
PawanMM
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Krishnakanth Goud
 

Similar to Hibernate (20)

Hibernate
HibernateHibernate
Hibernate
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
 
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
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
 
Hibernate - Part 2
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2
 
Hibernate
HibernateHibernate
Hibernate
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
Hibernate training-topics
Hibernate training-topicsHibernate training-topics
Hibernate training-topics
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
 
Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 

Recently uploaded

writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Diana Rendina
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 

Hibernate

  • 2. Content covered • Introduction to Hibernate • Hibernate Architecture • O/R Mapping in Hibernate
  • 4. Configuration (org.hibernate.cfg.Configuration) • The Configuration object, as seen in the example code, is the first Hibernate object you use. It represents a configuration or properties file for Hibernate. The Configuration object is usually created once during application initialization. • The Configuration object reads and establishes the properties Hibernate uses to get connected to a database and configure itself for work. A Configuration object is used to create a SessionFactory and then typically is discarded.
  • 5. Example <?xml version="1.0" encoding="UTF-8"?> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class"> org.hsqldb.jdbcDriver </property> <property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost </property> <property name="hibernate.connection.username">sa</property> <property name="connection.password"></property> <property name="connection.pool_size">1</property> <property name="hibernate.dialect"> org.hibernate.dialect.HSQLDialect </property> <mapping resource="com/vaannila/student/Student.hbm.xml"/> <mapping resource="com/vaannila/student/Address.hbm.xml"/> </session-factory> </hibernate-configuration>
  • 6. SessionFactory (org.hibernate.SessionFactory) • Created from a Configuration object, and as its name implies it is a factory for Session objects. • An expensive object to create. It, like the Configuration object, is usually created during application start up. However, unlike the Configuration object, It should be created once and kept for later use.
  • 7. SessionFactory • SessionFactory object, – used by all the threads of an application. It is a thread safe object. – One SessionFactory object is created per database. – Multiple SessionFactory objects (each requiring a separate Configuration) are created when connecting to multiple databases.
  • 9. Session (org.hibernate.Session) • Provide the main interface to accomplish work with the database. Persistent objects are saved and retrieved through a Session object. • Lightweight & inexpensive to create, does the work of getting a physical connection to the database. • Not thread safe. Therefore, session objects should not be kept open for a long time. • Applications create and destroy these as needed. • When modifications are made to the database, Session objects create a Transaction object.
  • 10. Transaction (org.hibernate.Transaction) • Represents a unit of work with the database (and potentially other systems). Transactions in Hibernate are handled by an underlying transaction manager and transaction (from JDBC, JTA or CORBA). • Abstracts the developer from having to deal with the underlying transaction manager/transaction. • Transaction objects should be kept open for as short of time as possible.
  • 11. Example Sessionsession= SessionFactory.newSession(); Transaction tx = session.beginTransaction( ); tx.commit(); tx.rollback(); session.close()
  • 12. Query & Criteria • Both objects are used to retrieve (and recreate) persistent objects. • Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database & create objects. • Criteria enables developer to create and execute the object-oriented criteria queries.
  • 13. Hibernate O/R Mapping • ORM is a technique to map object- oriented data with the relational data. • Used to convert datatype supported in object-oriented programming language to a datatype to a data type supported by a database. (if mapping is not provided, exception is thrown while transferring an object oriented data to the database)
  • 14. Hibernate O/R Mapping • Mapping in the format that relate – Classes with tables. – Properties with columns – SQL types with Java types. • O/R Mapping can be written for any database that can be oracle, DB2, MySql, Sybase.
  • 15. Hibernate O/R Mapping • xml file XML mapping documents allows you to: – Bridge the gap between object-oriented systems and relational databases – Define the object-relational mapping – Help to generate and export database table
  • 16. Associations strategies • Mainly 3 Association strategies available in O/R mapping: • 1. One-2-one • 2. One-2-many • 3. Many-2-one • 4. Many-2-many
  • 17. Hibernate Mapping files <?xml version="1.0"?> <hibernate-mapping> <class name="com.vaannila.student.Student" table="STUDENT"> <id name="studentId" type="long" column="STUDENT_ID"> <generator class="native“/></id> <property name="studentName" type="string" not-null="true" length="100" column="STUDENT_NAME" /> <many-to-one name="studentAddress" class="com.vaannila.student.Address" column="STUDENT_ADDRESS" not-null="true" cascade="all" unique="true" /> </class> </hibernate-mapping>