SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
Hibernate
Object/Relational Mapping and Transparent
Object Persistence for Java and SQL Databases
Facts about Hibernate
True transparent persistence
Query language aligned with SQL
Does not use byte code enhancement
Free/open source
What is Hibernate?
** Hibernate is a powerful, ultra-high performance object/relational
persistence and query service for Java. Hibernate lets you develop
persistent objects following common Java idiom - including association,
inheritance, polymorphism, composition and the Java collections
framework. Extremely fine-grained, richly typed object models are
possible. The Hibernate Query Language, designed as a "minimal"
object-oriented extension to SQL, provides an elegant bridge between
the object and relational worlds. Hibernate is now the most popular
ORM solution for Java.
** http://www.hibernate.org
Object-relational
impedance mismatch
Object databases are not the answer
Application Objects cannot be easily
persisted to relational databases
Similar to the putting square peg into round
hole
Object/Relational
Mapping (ORM)
Mapping application objects to relational
database
Solution for infamous object-relational
impedance mismatch
Finally application can focus on objects
Transparent Persistence
Persist application objects without knowing
what relational database is the target
Persist application objects without
“flattening” code weaved in and out of
business logic
Query Service
Ability to retrieve sets of data based on
criteria
Aggregate operations like count, sum, min,
max, etc.
Why use Hibernate?
Simple to get up and running
Transparent Persistence achieved using
Reflection
Isn’t intrusive to the build/deploy process
Persistence objects can follow common java
idioms: Association, Inheritance,
Polymorphism, Composition, Collections
In most cases Java objects do not even know
they can be persisted
Why use Hibernate
cont
Java developer can focus on object modeling
Feels much more natural than Entity Beans or
JDBC coding
Query mechanism closely resembles SQL so
learning curve is low
What makes up a
Hibernate application?
Standard domain objects defined in Java as
POJO’s, nothing more.
Hibernate mapping file
Hibernate configuration file
Hibernate Runtime
Database
What is missing from a
Hibernate application?
Flattening logic in Java code to conform to
relational database design
Inflation logic to resurrect Java object from
persistent store
Database specific tweaks
Hibernate Classes
SessionFactory - One instance per app.
Creates Sessions. Consumer of hibernate
configuration file.
Session - Conversation between application
and Hibernate
Transaction Factory - Creates transactions to
be used by application
Transaction - Wraps transaction
implementation(JTA, JDBC)
Hibernate Sample App
Standard Struts Web Application
Deployed on JBoss
Persisted to MySQL database
All hand coded, didn’t use automated tools to
generate Java classes, DDL, or mapping files
Disclaimer: Made simple stupid on purpose
DVD Library
Functions
Add DVD’s to your collection
Output your collection
Separation of
Responsibility
Struts
Action
JSP
Persistence
classes
DVD POJO
public class DVD {
private Long id;
private String name;
private String url;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
..
..
}
NOTE:
I transform
the DVDForm Bean to DVD
prior to persisting for
added flexibility
Hibernate Mapping File
DVD.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.shoesobjects.DVD" table="dvdlist">
<id name="id" column="id" type="java.lang.Long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name" column="name" type="java.lang.String" not-null="true"/>
<property name="url" column="url" type="java.lang.String"/>
</class>
</hibernate-mapping>
Hibernate.properties
#################
### Platforms ########
#################
## JNDI Datasource
hibernate.connection.datasource java:/DVDDB
## MySQL
hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class org.gjt.mm.mysql.Driver
hibernate.connection.driver_class com.mysql.jdbc.Driver
DVDService Class
public void updateDVD(DVD dvd) {
Session session = ConnectionFactory.getInstance().getSession();
try {
Transaction tx = session.beginTransaction();
session.update(dvd);
tx.commit();
session.flush();
} catch (HibernateException e) {
tx.rollback();
} finally {
// Cleanup
}
}
ConnectionFactory
public class ConnectionFactory {
private static ConnectionFactory instance = null;
private SessionFactory sessionFactory = null;
private ConnectionFactory() {
try {
Configuration cfg = new Configuration().addClass(DVD.class);
sessionFactory = cfg.buildSessionFactory();
} catch (Exception e) {
// Do something useful
}
}
public Session getSession() {
Session session = null;
try {
session = sessionFactory.openSession();
} catch (HibernateException e) {
// Do Something useful
}
return session;
}
ConnectionFactory
Improvedpublic class ConnectionFactory {
private static ConnectionFactory instance = null;
private SessionFactory sessionFactory = null;
private ConnectionFactory() {
try {
Configuration cfg = new Configuration().configure().buildSessionFactory();
} catch (Exception e) {
// Do something useful
}
}
public Session getSession() {
Session session = null;
try {
session = sessionFactory.openSession();
} catch (HibernateException e) {
// Do Something useful
}
return session;
}
Hibernate.cfg.xml
Alternative to hibernate.properties
Handles bigger applications better
Bind SessionFactory to JNDI Naming
Allows you to remove code like the following
and put it in a configuration file
Configuration cfg = new Configuration().addClass(DVD.class);
Sample
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="java:comp/env/hibernate/SessionFactory">
<property name="connection.datasource">java:/SomeDB</property>
<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="use_outer_join">true</property>
<property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<!-- Mapping files -->
<mapping resource="com/shoesobjects/SomePOJO.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Schema Generation
SchemaExport can generate or execute DDL
to generate the desired database schema
Can also update schema
Can be called via ant task
Code Generation
hbm2java
Parses hibernate mapping files and generates
POJO java classes on the fly.
Can be called via ant task
Mapping File Generation
MapGenerator - part of Hibernate extensions
Generates mapping file based on compiled
classes. Some rules apply.
Does repetitive grunt work
Links to live by
http://www.hibernate.org
http://www.springframework.org
http://www.jboss.org
http://raibledesigns.com/wiki/Wiki.jsp?
page=AppFuse

Weitere ähnliche Inhalte

Was ist angesagt?

Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Trainingsourabh aggarwal
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architectureAnurag
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate FrameworkRaveendra R
 
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 examplesecosio GmbH
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentationManav Prasad
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginnersRahul Jain
 
Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)ejlp12
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationKhoa Nguyen
 
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 Examplekamal kotecha
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer ReferenceMuthuselvam RS
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPASubin Sugunan
 
Spring (1)
Spring (1)Spring (1)
Spring (1)Aneega
 

Was ist angesagt? (20)

Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
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
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginners
 
Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)
 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - Presentation
 
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
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPA
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
 

Andere mochten auch

Cấu hình Hibernate
Cấu hình HibernateCấu hình Hibernate
Cấu hình HibernateMinh Quang
 
Hướng dẫn lập trình java hibernate cho người mới bắt đầu
Hướng dẫn lập trình java hibernate cho người mới bắt đầuHướng dẫn lập trình java hibernate cho người mới bắt đầu
Hướng dẫn lập trình java hibernate cho người mới bắt đầuThành Phạm Đức
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewBrett Meyer
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate FrameworkPhuoc Nguyen
 

Andere mochten auch (6)

iBATIS
iBATISiBATIS
iBATIS
 
Cấu hình Hibernate
Cấu hình HibernateCấu hình Hibernate
Cấu hình Hibernate
 
Hướng dẫn lập trình java hibernate cho người mới bắt đầu
Hướng dẫn lập trình java hibernate cho người mới bắt đầuHướng dẫn lập trình java hibernate cho người mới bắt đầu
Hướng dẫn lập trình java hibernate cho người mới bắt đầu
 
Presentation JPA
Presentation JPAPresentation JPA
Presentation JPA
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 

Ähnlich wie Hibernate presentation

hibernate-presentation-1196607644547952-4.pdf
hibernate-presentation-1196607644547952-4.pdfhibernate-presentation-1196607644547952-4.pdf
hibernate-presentation-1196607644547952-4.pdfMytrux1
 
Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1PawanMM
 
Hibernate - Part 2
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2 Hitesh-Java
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2PawanMM
 
Hibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaHibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaEdureka!
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1Hitesh-Java
 
Java hibernate orm implementation tool
Java hibernate   orm implementation toolJava hibernate   orm implementation tool
Java hibernate orm implementation tooljavaease
 
Learn HIBERNATE at ASIT
Learn HIBERNATE at ASITLearn HIBERNATE at ASIT
Learn HIBERNATE at ASITASIT
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggetsVirtual Nuggets
 
Hibernate basics
Hibernate basicsHibernate basics
Hibernate basicsAathikaJava
 
Java Hibernate Basics
Java Hibernate BasicsJava Hibernate Basics
Java Hibernate BasicsDeeptiJava
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questionsDhiraj Champawat
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)Montreal JUG
 
MVC and Entity Framework
MVC and Entity FrameworkMVC and Entity Framework
MVC and Entity FrameworkJames Johnson
 

Ähnlich wie Hibernate presentation (20)

hibernate-presentation-1196607644547952-4.pdf
hibernate-presentation-1196607644547952-4.pdfhibernate-presentation-1196607644547952-4.pdf
hibernate-presentation-1196607644547952-4.pdf
 
Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
 
Hibernate - Part 2
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
 
Hibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaHibernate Interview Questions | Edureka
Hibernate Interview Questions | Edureka
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1
 
Java hibernate orm implementation tool
Java hibernate   orm implementation toolJava hibernate   orm implementation tool
Java hibernate orm implementation tool
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
Learn HIBERNATE at ASIT
Learn HIBERNATE at ASITLearn HIBERNATE at ASIT
Learn HIBERNATE at ASIT
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
 
Hibernate
HibernateHibernate
Hibernate
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
Hibernate basics
Hibernate basicsHibernate basics
Hibernate basics
 
Java Hibernate Basics
Java Hibernate BasicsJava Hibernate Basics
Java Hibernate Basics
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)
 
MVC and Entity Framework
MVC and Entity FrameworkMVC and Entity Framework
MVC and Entity Framework
 

Mehr von Luis Goldster

Ruby on rails evaluation
Ruby on rails evaluationRuby on rails evaluation
Ruby on rails evaluationLuis Goldster
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksLuis Goldster
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.pptLuis Goldster
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data miningLuis Goldster
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data miningLuis Goldster
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discoveryLuis Goldster
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherenceLuis Goldster
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cacheLuis Goldster
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching worksLuis Goldster
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsLuis Goldster
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisLuis Goldster
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaLuis Goldster
 

Mehr von Luis Goldster (20)

Ruby on rails evaluation
Ruby on rails evaluationRuby on rails evaluation
Ruby on rails evaluation
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
 
Ado.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworksAdo.net &amp; data persistence frameworks
Ado.net &amp; data persistence frameworks
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
 
Cache recap
Cache recapCache recap
Cache recap
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Api crash
Api crashApi crash
Api crash
 
Object model
Object modelObject model
Object model
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Abstract class
Abstract classAbstract class
Abstract class
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Kürzlich hochgeladen (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

Hibernate presentation

  • 1. Hibernate Object/Relational Mapping and Transparent Object Persistence for Java and SQL Databases
  • 2. Facts about Hibernate True transparent persistence Query language aligned with SQL Does not use byte code enhancement Free/open source
  • 3. What is Hibernate? ** Hibernate is a powerful, ultra-high performance object/relational persistence and query service for Java. Hibernate lets you develop persistent objects following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework. Extremely fine-grained, richly typed object models are possible. The Hibernate Query Language, designed as a "minimal" object-oriented extension to SQL, provides an elegant bridge between the object and relational worlds. Hibernate is now the most popular ORM solution for Java. ** http://www.hibernate.org
  • 4. Object-relational impedance mismatch Object databases are not the answer Application Objects cannot be easily persisted to relational databases Similar to the putting square peg into round hole
  • 5. Object/Relational Mapping (ORM) Mapping application objects to relational database Solution for infamous object-relational impedance mismatch Finally application can focus on objects
  • 6. Transparent Persistence Persist application objects without knowing what relational database is the target Persist application objects without “flattening” code weaved in and out of business logic
  • 7. Query Service Ability to retrieve sets of data based on criteria Aggregate operations like count, sum, min, max, etc.
  • 8. Why use Hibernate? Simple to get up and running Transparent Persistence achieved using Reflection Isn’t intrusive to the build/deploy process Persistence objects can follow common java idioms: Association, Inheritance, Polymorphism, Composition, Collections In most cases Java objects do not even know they can be persisted
  • 9. Why use Hibernate cont Java developer can focus on object modeling Feels much more natural than Entity Beans or JDBC coding Query mechanism closely resembles SQL so learning curve is low
  • 10. What makes up a Hibernate application? Standard domain objects defined in Java as POJO’s, nothing more. Hibernate mapping file Hibernate configuration file Hibernate Runtime Database
  • 11. What is missing from a Hibernate application? Flattening logic in Java code to conform to relational database design Inflation logic to resurrect Java object from persistent store Database specific tweaks
  • 12. Hibernate Classes SessionFactory - One instance per app. Creates Sessions. Consumer of hibernate configuration file. Session - Conversation between application and Hibernate Transaction Factory - Creates transactions to be used by application Transaction - Wraps transaction implementation(JTA, JDBC)
  • 13. Hibernate Sample App Standard Struts Web Application Deployed on JBoss Persisted to MySQL database All hand coded, didn’t use automated tools to generate Java classes, DDL, or mapping files Disclaimer: Made simple stupid on purpose
  • 14. DVD Library Functions Add DVD’s to your collection Output your collection
  • 16. DVD POJO public class DVD { private Long id; private String name; private String url; public Long getId() { return id; } public void setId(Long id) { this.id = id; } .. .. } NOTE: I transform the DVDForm Bean to DVD prior to persisting for added flexibility
  • 17. Hibernate Mapping File DVD.hbm.xml <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="com.shoesobjects.DVD" table="dvdlist"> <id name="id" column="id" type="java.lang.Long" unsaved-value="null"> <generator class="native"/> </id> <property name="name" column="name" type="java.lang.String" not-null="true"/> <property name="url" column="url" type="java.lang.String"/> </class> </hibernate-mapping>
  • 18. Hibernate.properties ################# ### Platforms ######## ################# ## JNDI Datasource hibernate.connection.datasource java:/DVDDB ## MySQL hibernate.dialect net.sf.hibernate.dialect.MySQLDialect hibernate.connection.driver_class org.gjt.mm.mysql.Driver hibernate.connection.driver_class com.mysql.jdbc.Driver
  • 19. DVDService Class public void updateDVD(DVD dvd) { Session session = ConnectionFactory.getInstance().getSession(); try { Transaction tx = session.beginTransaction(); session.update(dvd); tx.commit(); session.flush(); } catch (HibernateException e) { tx.rollback(); } finally { // Cleanup } }
  • 20. ConnectionFactory public class ConnectionFactory { private static ConnectionFactory instance = null; private SessionFactory sessionFactory = null; private ConnectionFactory() { try { Configuration cfg = new Configuration().addClass(DVD.class); sessionFactory = cfg.buildSessionFactory(); } catch (Exception e) { // Do something useful } } public Session getSession() { Session session = null; try { session = sessionFactory.openSession(); } catch (HibernateException e) { // Do Something useful } return session; }
  • 21. ConnectionFactory Improvedpublic class ConnectionFactory { private static ConnectionFactory instance = null; private SessionFactory sessionFactory = null; private ConnectionFactory() { try { Configuration cfg = new Configuration().configure().buildSessionFactory(); } catch (Exception e) { // Do something useful } } public Session getSession() { Session session = null; try { session = sessionFactory.openSession(); } catch (HibernateException e) { // Do Something useful } return session; }
  • 22. Hibernate.cfg.xml Alternative to hibernate.properties Handles bigger applications better Bind SessionFactory to JNDI Naming Allows you to remove code like the following and put it in a configuration file Configuration cfg = new Configuration().addClass(DVD.class);
  • 23. Sample hibernate.cfg.xml <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"> <hibernate-configuration> <!-- a SessionFactory instance listed as /jndi/name --> <session-factory name="java:comp/env/hibernate/SessionFactory"> <property name="connection.datasource">java:/SomeDB</property> <property name="show_sql">true</property> <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property> <property name="use_outer_join">true</property> <property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</> <property name="jta.UserTransaction">java:comp/UserTransaction</property> <!-- Mapping files --> <mapping resource="com/shoesobjects/SomePOJO.hbm.xml"/> </session-factory> </hibernate-configuration>
  • 24. Schema Generation SchemaExport can generate or execute DDL to generate the desired database schema Can also update schema Can be called via ant task
  • 25. Code Generation hbm2java Parses hibernate mapping files and generates POJO java classes on the fly. Can be called via ant task
  • 26. Mapping File Generation MapGenerator - part of Hibernate extensions Generates mapping file based on compiled classes. Some rules apply. Does repetitive grunt work
  • 27. Links to live by http://www.hibernate.org http://www.springframework.org http://www.jboss.org http://raibledesigns.com/wiki/Wiki.jsp? page=AppFuse