SlideShare a Scribd company logo
Intro to HibernateIntro to Hibernate
 "Hibernate is an object/relational mapping 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." -- Preface Hibernate
Documentation
 Hibernate supports many different relational databases.
 Many other open source tools use Hibernate as their
persistence layer.
 Hibernate includes tools to make O/R persistence an
integrated part of the build process.
Intro to HibernateIntro to Hibernate
IANAHE - I am NOT an Hibernate
Expert.
Intro to Hibernate: ObjectivesIntro to Hibernate: Objectives
This presentation will consist of some
background information on Hibernate and
some complete examples that show the
basic functionality of Hibernate.
Obviously there is more than one way to use
Hibernate.
Hibernate BasicsHibernate Basics
Hibernate BasicsHibernate Basics
SessionFactory
A threadsafe (immutable) cache of
compiled mappings for a single
database.
A factory for Session.
Expensive to create.
Hibernate BasicsHibernate Basics
Session
A single-threaded, short-lived object
representing a conversation between
the application and the persistent
store.
Wraps a JDBC connection.
Factory for Transaction.
Holds a mandatory (first-level) cache
of persistent objects, used when
navigating the object graph or looking
up objects by identifier.
Hibernate BasicsHibernate Basics
Persistent Objects and
Collections
Short-lived, single threaded objects
containing persistent state and
business function.
These might be ordinary
JavaBeans/POJOs, the only special
thing about them is that they are
currently associated with (exactly one)
Session.
As soon as the Session is closed, they
will be detached and free to use in any
application layer (e.g. directly as data
transfer objects to and from
presentation).
Hibernate BasicsHibernate Basics
Transient Objects and
Collections
Instances of persistent classes that
are not currently associated with a
Session.
They may have been instantiated by
the application and not (yet) persisted
or they may have been instantiated by
a closed Session.
Hibernate BasicsHibernate Basics
Transaction
(Optional) A single-threaded, short-
lived object used by the application to
specify atomic units of work.
Abstracts application from underlying
JDBC, JTA or CORBA transaction.
Multiple transactions per Session.
Hibernate BasicsHibernate Basics
ConnectionProvider
(Optional) A factory for (and pool
of) JDBC connections. Abstracts
application from underlying
Datasource or DriverManager.
Not exposed to application, but
can be extended/implemented by
the developer.
TransactionFactory
(Optional) A factory for
Transaction instances. Not
exposed to the application, but
can be extended/implemented by
the developer.
Hibernate ToolsHibernate Tools
The Hibernate Mapping File
Database Schema Generation
net.sf.hibernate.tool.hbm2ddl.SchemaExportTask
net.sf.hibernate.tool.hbm2ddl.SchemaUpdateTask
Best Practices suggest having one file per entity.
Java Code Generation
net.sf.hibernate.tool.hbm2java.Hbm2JavaTask
Hibernate ToolsHibernate Tools
The Hibernate Mapping File Best Practices suggest having one file per entity.
Database Schema Reverse Engineering
(Bottom Up development)
Middlegen
Object Driven Design
(Top Down development)
AndroMDA
XMI -> *.hbm.xml
XDoclet can also be used to
directly embed the mapping file
information in the source code.
Hibernate ConfigurationHibernate Configuration
hibernate.properties
hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
## in Ant you can get away with a relative path
## however using this through Eclipse requires an explicit path
hibernate.connection.url=
jdbc:hsqldb:c:/workspace/HibernateNotebook/data/music
hibernate.connection.username=sa
hibernate.connection.password=
Hibernate ConfigurationHibernate Configuration
Currently supported Dialects
DB2390Dialect DB2400Dialect DB2Dialect FirebirdDialect
FrontBaseDialect GenericDialect HSQLDialect
Informix9Dialect InformixDialect IngresDialect
InterbaseDialect MckoiDialect MySQLDialect
NoArgSQLFunction Oracle9Dialect OracleDialect
PointbaseDialect PostgreSQLDialect ProgressDialect
SAPDBDialect SQLServerDialect StandardSQLFunction
Sybase11_9_2Dialect SybaseAnywhereDialect SybaseDialect
Or you can choose to extend the Abstract Dialect object to add support to
whatever database you are using. A Dialect “Represents a dialect of SQL
implemented by a particular RDBMS. Subclasses implement Hibernate
compatibility with different systems.” -- Hibernate Documentation
Hibernate Mapping FilesHibernate Mapping Files
*.hbm.xml*.hbm.xml
Problem Statement:
Create a database system to store electronic music files from various
sources. We need to keep track of individual tracks, who performed them,
and comments for each track.
This example is taken primarily from the example presented in “Hibernate:
A Developer's Notebook” by James Elliot.
Any similarities are intentional; any differences are either mistakes or
modifications made for clarification.
Assumption: We are looking only at data objects and their relationships no
"business" logic will be considered.
Hibernate Mapping FilesHibernate Mapping Files
Track
id: int
title: String
filePath: String
playTime: Date
added: Date
volume: short
comments: Set
artists: Set
Artist
id: int
name: String
tracks: Set
This is a Many-To-Many relationship:
An artist can have many tracks and a track can
be created by several artists.
String: comment This is a one to many relationship: a Track has
multiple comments. (Composite object)
Hibernate Mapping File DemoHibernate Mapping File Demo
 Mapping file structure
 Schema Generation
 Code Generation
 Populate the database with records
 Query the records
 Modify existing records
 Delete Records
ReferencesReferences
 http://www.hibernate.org/
 http://boss.bekk.no/boss/middlegen/
 http://www.andromda.org/
 http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-tags.html
 Email- tyler@mendenhallway.com
Please no Spam just questions.
Questions?Questions?
Ad

More Related Content

What's hot (20)

Hibernate
HibernateHibernate
Hibernate
Prashant Kalkar
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
Akshay Ballarpure
 
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
Jitender Singh Lodhi
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
chakrapani tripathi
 
Validation controls ASP .NET
Validation controls ASP .NETValidation controls ASP .NET
Validation controls ASP .NET
baabtra.com - No. 1 supplier of quality freshers
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
Information Technology
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
Knoldus Inc.
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Bootstrap 5 basic
Bootstrap 5 basicBootstrap 5 basic
Bootstrap 5 basic
Jubair Ahmed Junjun
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long
 
Hibernate
HibernateHibernate
Hibernate
Ajay K
 
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
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
ecosio GmbH
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginners
Rahul Jain
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
Rohit Jain
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
Santosh Kumar Kar
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
Armen Arzumanyan
 

Similar to Introduction to Hibernate (20)

Java hibernate orm implementation tool
Java hibernate   orm implementation toolJava hibernate   orm implementation tool
Java hibernate orm implementation tool
javaease
 
Learn HIBERNATE at ASIT
Learn HIBERNATE at ASITLearn HIBERNATE at ASIT
Learn HIBERNATE at ASIT
ASIT
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
kanchanmahajan23
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
kanchanmahajan23
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
kanchanmahajan23
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
Rajiv Gupta
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
Virtual Nuggets
 
Hibernate
HibernateHibernate
Hibernate
Murali Pachiyappan
 
Hibernate
HibernateHibernate
Hibernate
reddivarihareesh
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
Muthuselvam RS
 
Hibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaHibernate Interview Questions | Edureka
Hibernate Interview Questions | Edureka
Edureka!
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
sourabh aggarwal
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Mayank Kumar
 
TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6
Lokesh Singrol
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
Mumbai Academisc
 
Hibernate training-topics
Hibernate training-topicsHibernate training-topics
Hibernate training-topics
Vibrant Technologies & Computers
 
Hibernate Interview Questions and Answers
Hibernate Interview Questions and AnswersHibernate Interview Questions and Answers
Hibernate Interview Questions and Answers
AnuragMourya8
 
Hibernate
HibernateHibernate
Hibernate
vaishnavmem
 
Hibernate.pdf
Hibernate.pdfHibernate.pdf
Hibernate.pdf
SaadAnsari73
 
Module-3 for career and JFSD ppt for study.pptx
Module-3 for career and JFSD ppt for study.pptxModule-3 for career and JFSD ppt for study.pptx
Module-3 for career and JFSD ppt for study.pptx
ViratKohli78
 
Java hibernate orm implementation tool
Java hibernate   orm implementation toolJava hibernate   orm implementation tool
Java hibernate orm implementation tool
javaease
 
Learn HIBERNATE at ASIT
Learn HIBERNATE at ASITLearn HIBERNATE at ASIT
Learn HIBERNATE at ASIT
ASIT
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
Virtual Nuggets
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
Muthuselvam RS
 
Hibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaHibernate Interview Questions | Edureka
Hibernate Interview Questions | Edureka
Edureka!
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
sourabh aggarwal
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Mayank Kumar
 
Hibernate Interview Questions and Answers
Hibernate Interview Questions and AnswersHibernate Interview Questions and Answers
Hibernate Interview Questions and Answers
AnuragMourya8
 
Module-3 for career and JFSD ppt for study.pptx
Module-3 for career and JFSD ppt for study.pptxModule-3 for career and JFSD ppt for study.pptx
Module-3 for career and JFSD ppt for study.pptx
ViratKohli78
 
Ad

More from Krishnakanth Goud (12)

Log4j
Log4jLog4j
Log4j
Krishnakanth Goud
 
Hibernate java and_oracle
Hibernate java and_oracleHibernate java and_oracle
Hibernate java and_oracle
Krishnakanth Goud
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Krishnakanth Goud
 
Persistence hibernate
Persistence hibernatePersistence hibernate
Persistence hibernate
Krishnakanth Goud
 
Mule smtp connector
Mule smtp connectorMule smtp connector
Mule smtp connector
Krishnakanth Goud
 
Fetch records from mysql using mule esb
Fetch records from mysql using mule esbFetch records from mysql using mule esb
Fetch records from mysql using mule esb
Krishnakanth Goud
 
Running ms sql stored procedures in mule
Running ms sql stored procedures in muleRunning ms sql stored procedures in mule
Running ms sql stored procedures in mule
Krishnakanth Goud
 
Web service invocation in mule
Web service invocation in muleWeb service invocation in mule
Web service invocation in mule
Krishnakanth Goud
 
Mule ESB Dropbox connector
Mule ESB Dropbox connectorMule ESB Dropbox connector
Mule ESB Dropbox connector
Krishnakanth Goud
 
Box connector Mule ESB Integration
Box connector Mule ESB IntegrationBox connector Mule ESB Integration
Box connector Mule ESB Integration
Krishnakanth Goud
 
Mule esb :Data Weave
Mule esb :Data WeaveMule esb :Data Weave
Mule esb :Data Weave
Krishnakanth Goud
 
Bluetooth
BluetoothBluetooth
Bluetooth
Krishnakanth Goud
 
Ad

Recently uploaded (20)

Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 

Introduction to Hibernate

  • 1. Intro to HibernateIntro to Hibernate  "Hibernate is an object/relational mapping 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." -- Preface Hibernate Documentation  Hibernate supports many different relational databases.  Many other open source tools use Hibernate as their persistence layer.  Hibernate includes tools to make O/R persistence an integrated part of the build process.
  • 2. Intro to HibernateIntro to Hibernate IANAHE - I am NOT an Hibernate Expert.
  • 3. Intro to Hibernate: ObjectivesIntro to Hibernate: Objectives This presentation will consist of some background information on Hibernate and some complete examples that show the basic functionality of Hibernate. Obviously there is more than one way to use Hibernate.
  • 5. Hibernate BasicsHibernate Basics SessionFactory A threadsafe (immutable) cache of compiled mappings for a single database. A factory for Session. Expensive to create.
  • 6. Hibernate BasicsHibernate Basics Session A single-threaded, short-lived object representing a conversation between the application and the persistent store. Wraps a JDBC connection. Factory for Transaction. Holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier.
  • 7. Hibernate BasicsHibernate Basics Persistent Objects and Collections Short-lived, single threaded objects containing persistent state and business function. These might be ordinary JavaBeans/POJOs, the only special thing about them is that they are currently associated with (exactly one) Session. As soon as the Session is closed, they will be detached and free to use in any application layer (e.g. directly as data transfer objects to and from presentation).
  • 8. Hibernate BasicsHibernate Basics Transient Objects and Collections Instances of persistent classes that are not currently associated with a Session. They may have been instantiated by the application and not (yet) persisted or they may have been instantiated by a closed Session.
  • 9. Hibernate BasicsHibernate Basics Transaction (Optional) A single-threaded, short- lived object used by the application to specify atomic units of work. Abstracts application from underlying JDBC, JTA or CORBA transaction. Multiple transactions per Session.
  • 10. Hibernate BasicsHibernate Basics ConnectionProvider (Optional) A factory for (and pool of) JDBC connections. Abstracts application from underlying Datasource or DriverManager. Not exposed to application, but can be extended/implemented by the developer. TransactionFactory (Optional) A factory for Transaction instances. Not exposed to the application, but can be extended/implemented by the developer.
  • 11. Hibernate ToolsHibernate Tools The Hibernate Mapping File Database Schema Generation net.sf.hibernate.tool.hbm2ddl.SchemaExportTask net.sf.hibernate.tool.hbm2ddl.SchemaUpdateTask Best Practices suggest having one file per entity. Java Code Generation net.sf.hibernate.tool.hbm2java.Hbm2JavaTask
  • 12. Hibernate ToolsHibernate Tools The Hibernate Mapping File Best Practices suggest having one file per entity. Database Schema Reverse Engineering (Bottom Up development) Middlegen Object Driven Design (Top Down development) AndroMDA XMI -> *.hbm.xml XDoclet can also be used to directly embed the mapping file information in the source code.
  • 13. Hibernate ConfigurationHibernate Configuration hibernate.properties hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect hibernate.connection.driver_class=org.hsqldb.jdbcDriver ## in Ant you can get away with a relative path ## however using this through Eclipse requires an explicit path hibernate.connection.url= jdbc:hsqldb:c:/workspace/HibernateNotebook/data/music hibernate.connection.username=sa hibernate.connection.password=
  • 14. Hibernate ConfigurationHibernate Configuration Currently supported Dialects DB2390Dialect DB2400Dialect DB2Dialect FirebirdDialect FrontBaseDialect GenericDialect HSQLDialect Informix9Dialect InformixDialect IngresDialect InterbaseDialect MckoiDialect MySQLDialect NoArgSQLFunction Oracle9Dialect OracleDialect PointbaseDialect PostgreSQLDialect ProgressDialect SAPDBDialect SQLServerDialect StandardSQLFunction Sybase11_9_2Dialect SybaseAnywhereDialect SybaseDialect Or you can choose to extend the Abstract Dialect object to add support to whatever database you are using. A Dialect “Represents a dialect of SQL implemented by a particular RDBMS. Subclasses implement Hibernate compatibility with different systems.” -- Hibernate Documentation
  • 15. Hibernate Mapping FilesHibernate Mapping Files *.hbm.xml*.hbm.xml Problem Statement: Create a database system to store electronic music files from various sources. We need to keep track of individual tracks, who performed them, and comments for each track. This example is taken primarily from the example presented in “Hibernate: A Developer's Notebook” by James Elliot. Any similarities are intentional; any differences are either mistakes or modifications made for clarification. Assumption: We are looking only at data objects and their relationships no "business" logic will be considered.
  • 16. Hibernate Mapping FilesHibernate Mapping Files Track id: int title: String filePath: String playTime: Date added: Date volume: short comments: Set artists: Set Artist id: int name: String tracks: Set This is a Many-To-Many relationship: An artist can have many tracks and a track can be created by several artists. String: comment This is a one to many relationship: a Track has multiple comments. (Composite object)
  • 17. Hibernate Mapping File DemoHibernate Mapping File Demo  Mapping file structure  Schema Generation  Code Generation  Populate the database with records  Query the records  Modify existing records  Delete Records
  • 18. ReferencesReferences  http://www.hibernate.org/  http://boss.bekk.no/boss/middlegen/  http://www.andromda.org/  http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-tags.html  Email- [email protected] Please no Spam just questions.