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?

More Related Content

PPTX
Hibernate Basic Concepts - Presentation
PPT
Hibernate architecture
PDF
Hibernate Presentation
PPTX
Object Oriented Programing JAVA presentaion
PPTX
Java database connectivity with MySql
PPTX
Spring Web MVC
PPTX
Hibernate ppt
PPTX
Functions in PHP.pptx
Hibernate Basic Concepts - Presentation
Hibernate architecture
Hibernate Presentation
Object Oriented Programing JAVA presentaion
Java database connectivity with MySql
Spring Web MVC
Hibernate ppt
Functions in PHP.pptx

What's hot (20)

PPTX
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
PDF
Spring boot
PDF
Spring Framework
PPTX
Introduction to Spring Framework
PPTX
Spring boot Introduction
PPS
Jdbc architecture and driver types ppt
PPTX
Java Swing
PPT
Php with MYSQL Database
PDF
Java I/o streams
PPTX
Spring mvc
PPT
Java database connectivity with MYSQL
PPSX
Spring - Part 1 - IoC, Di and Beans
PDF
Spring Boot
PPTX
Spring boot
PDF
Being Functional on Reactive Streams with Spring Reactor
PPTX
Introduction to java 8 stream api
PPTX
Mongoose and MongoDB 101
PDF
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
PPTX
CSharp Presentation
PPT
Introduction to hibernate
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Spring boot
Spring Framework
Introduction to Spring Framework
Spring boot Introduction
Jdbc architecture and driver types ppt
Java Swing
Php with MYSQL Database
Java I/o streams
Spring mvc
Java database connectivity with MYSQL
Spring - Part 1 - IoC, Di and Beans
Spring Boot
Spring boot
Being Functional on Reactive Streams with Spring Reactor
Introduction to java 8 stream api
Mongoose and MongoDB 101
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
CSharp Presentation
Introduction to hibernate
Ad

Similar to Introduction to Hibernate (20)

PPT
Java hibernate orm implementation tool
PPT
Learn HIBERNATE at ASIT
DOCX
What is hibernate?
PPT
What is hibernate?
PDF
What is hibernate?
PPTX
Hibernate in Action
PDF
Hibernate 3
PDF
Free Hibernate Tutorial | VirtualNuggets
PPT
PPS
Java Hibernate Programming with Architecture Diagram and Example
PPT
Hibernate
ODP
Hibernate Developer Reference
PDF
Hibernate Interview Questions | Edureka
ODP
Hibernate complete Training
PPT
Hibernate Interview Questions
DOCX
TY.BSc.IT Java QB U6
PPTX
Hibernate tutorial
PPT
Hibernate training-topics
PDF
Hibernate Interview Questions and Answers
PPT
Hibernate
Java hibernate orm implementation tool
Learn HIBERNATE at ASIT
What is hibernate?
What is hibernate?
What is hibernate?
Hibernate in Action
Hibernate 3
Free Hibernate Tutorial | VirtualNuggets
Java Hibernate Programming with Architecture Diagram and Example
Hibernate
Hibernate Developer Reference
Hibernate Interview Questions | Edureka
Hibernate complete Training
Hibernate Interview Questions
TY.BSc.IT Java QB U6
Hibernate tutorial
Hibernate training-topics
Hibernate Interview Questions and Answers
Hibernate
Ad

More from Krishnakanth Goud (12)

PPT
Hibernate java and_oracle
PPT
Hibernate presentation
PPT
Persistence hibernate
ODP
Mule smtp connector
ODP
Fetch records from mysql using mule esb
ODP
Running ms sql stored procedures in mule
ODP
Web service invocation in mule
ODP
Mule ESB Dropbox connector
ODP
Box connector Mule ESB Integration
PPTX
Mule esb :Data Weave
PPT
Hibernate java and_oracle
Hibernate presentation
Persistence hibernate
Mule smtp connector
Fetch records from mysql using mule esb
Running ms sql stored procedures in mule
Web service invocation in mule
Mule ESB Dropbox connector
Box connector Mule ESB Integration
Mule esb :Data Weave

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
master seminar digital applications in india
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Types and Its function , kingdom of life
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
Supply Chain Operations Speaking Notes -ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
STATICS OF THE RIGID BODIES Hibbelers.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
TR - Agricultural Crops Production NC III.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
GDM (1) (1).pptx small presentation for students
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Abdominal Access Techniques with Prof. Dr. R K Mishra
Insiders guide to clinical Medicine.pdf
Institutional Correction lecture only . . .
master seminar digital applications in india
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Types and Its function , kingdom of life
VCE English Exam - Section C Student Revision Booklet
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPH.pptx obstetrics and gynecology in nursing

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- tyler@mendenhallway.com Please no Spam just questions.