SlideShare a Scribd company logo
1 of 19
CONTENTS
1. Overview
2. Advantages over JDBC
3. Hibernate Architecture
4. Downloading and Installing Hibernate
Overview
• A popular open source Object Relational Mapping(ORM) tool which
provides transparent persistence for POJOS.
• ORM is used to map objects to relational databases(Oracle,Mysql).
• Allows to map java objects to relational databases and also provides data
query
• Generates the SQL calls and makes application portable to all SQL
databases, with database portability
• Allows to develop persistent classes with all java terms – like association,
inheritance, polymorphism etc
• Can be used as in standalone Java applications or as in Java EE
applications using servlets or EJB session beans.
Advantages of Hibernate
• Retains natural object model (transparent)
• Minimizes Code
• Does not require a container
• Model is not tied to persistence implementation.
• Metadata controlled persistence
• Transparent - working with the model, not the data access technology
• Pooling, Caching, Transactions can be handled outside of our code
• Object/relational mappings are defined in an XML document. The
mapping document is designed to be readable and hand-editable.
• Mapping language is Java-centric, meaning that mappings are
constructed around persistent class declarations, not table declarations.
• Choose to define XML mappings by hand, or by using tools like XDoclet,
Middlegen and AndroMDA.
• The “Lite" architecture has the application provide its own
JDBC connections and manage its own transactions
• Has
– SessionFactory
– Session
– Persistent Objects
– Transient Objects
• The "full cream" architecture abstracts the application away
from the underlying JDBC and Java Transaction API (JTA) and
lets Hibernate take care of the details
Configuration
Configuration class's operation has two key components:
• The database connection
– handled through one or more configuration files supported by
Hibernate
– hibernate.properties and hibernate.cfg.xml
• The classmapping setup
– makes the connection between the Java classes and database tables.
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>
<session-factory>
<property name="connection.driver">
com.mysql.jdbc.Driver </property>
<property name="connection.url“>
jdbc:mysql://localhost/products </property>
<property name="dialect">
net.sf.hibernate.dialect.MySQLDialect </property>
</session-factory>
</hibernate-configuration>
hibernate.properties
hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost/products
hibernate.connection.username root
hibernate.connection.password root
hibernate.show_sql true
hibernate.cglib.use_reflection_optimizer false
Hibernate mapping file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="Notes“ table="notes">
<id name="id" unsaved-value="0">
<generator class="native"/></id>
<property name="info" type="string"/>
<property name="count" type="integer" not-null="true"/>
<property name="zipcode" type="string"/>
<property name="fullname" type="string"/>
</class></hibernate-mapping>
Hibernate Architecture
• Basic interfaces used while working with Hibernate are:
- SessionFactory
- Session
- Transaction
SessionFactory
• A singleton class called SessionFactory is instantiated.
• A threadsafe, immutable cache of compiled mappings for a single
database.
• The SessionFactory object is heavyweight; better to create only one
SessionFactory per application.
• A factory for creating session objects
• Can hold an optional(second-level) cache of data that is reusable between
transactions at a process
Session
• A single-threaded, short-lived object representing a conversation between
the application and the persistent store.
• is lightweight and instantiated each time an interaction is needed with
the database.
• As the Session object is created, the objects are persisted or loaded from
the database
• Then the session object is flushed and closed.
• It wraps a JDBC connection and is a factory for Transaction.
• Opened by SessionFactory.openSession()
• Closed by session.close()
ThreadLocal Session Pattern
• Use ThreadLocal variable to maintain session data
ThreadLocal
• Specialized Java class which is associated to a user thread of execution and
serves as a data container throughout the lifespan of the thread (or child
threads)
• Global variable which is local for every thread
• To create a thread
ThreadLocal sess = new ThreadLocal();
Session session = sess.get(); // to get the current session
Transaction
• A single-threaded, short-lived object used by the application
to specify atomic units of work.
• It abstracts the application from the underlying JDBC, JTA or
CORBA transaction.
• A Session might span several Transactions in some cases. is
connected with a concrete session
Transaction tx = session.beginTransaction( );
Persistent objects and collections(Entities)
• Short-lived, single threaded objects containing persistent
state and business function.
• Can be ordinary JavaBeans/POJOs.
• associated with exactly one Session.
Transient and detached objects and collections
• Instances of persistent classes that are not currently
associated with a Session.
• Might have been instantiated by the application and not yet
persisted
• Might have been instantiated by a closed Session.
Hibernate Callbacks
• public Boolean onSave(Session s); - called before the object is saved to the
• database
• public Boolean onUpdate(Session s); - called before the object is updated
• public boolean onDelete(Session s); - called before the object is deleted
• public Boolean onLoad(Session s); - called after the object is loaded from
• the database
Downloading and Installing
Downloading
• Download Hibernate from the site (ie) from JBoss tools as Zip
• Extract the files to your preferred location
• Has 2 folders – plugins and features
Adding to Eclipse
• Add the files within hibernate /features folder to
eclipse/features folder
• Add the files within hibernate /plugins folder to
eclipse/plugins folder
Alternate Way
• Open eclipse Help  Update site add hibernate from site

More Related Content

What's hot

Hibernate
HibernateHibernate
HibernateAjay K
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization Hitesh-Java
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer ReferenceMuthuselvam RS
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1Hitesh-Java
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Introduction To Hibernate
Introduction To HibernateIntroduction To Hibernate
Introduction To Hibernateashishkulkarni
 
Session 35 - Design Patterns
Session 35 - Design PatternsSession 35 - Design Patterns
Session 35 - Design PatternsPawanMM
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction Hitesh-Java
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2PawanMM
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questionsArun Vasanth
 
Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeAndrus Adamchik
 
Spring db-access mod03
Spring db-access mod03Spring db-access mod03
Spring db-access mod03Guo Albert
 

What's hot (18)

Hibernate
HibernateHibernate
Hibernate
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
 
Hibernate - Part 1
Hibernate - Part 1Hibernate - Part 1
Hibernate - Part 1
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Introduction To Hibernate
Introduction To HibernateIntroduction To Hibernate
Introduction To Hibernate
 
Session 35 - Design Patterns
Session 35 - Design PatternsSession 35 - Design Patterns
Session 35 - Design Patterns
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questions
 
Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM Alternative
 
Spring db-access mod03
Spring db-access mod03Spring db-access mod03
Spring db-access mod03
 
Persistence hibernate
Persistence hibernatePersistence hibernate
Persistence hibernate
 
Hibernate
HibernateHibernate
Hibernate
 

Similar to Hibernate

Similar to Hibernate (20)

Hibernate
HibernateHibernate
Hibernate
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
 
Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introduction
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jj
 
Hibernate training-topics
Hibernate training-topicsHibernate training-topics
Hibernate training-topics
 
NiFi - First approach
NiFi - First approachNiFi - First approach
NiFi - First approach
 
Hibernate Session 1
Hibernate Session 1Hibernate Session 1
Hibernate Session 1
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate.pdf
Hibernate.pdfHibernate.pdf
Hibernate.pdf
 
OpenProdoc Overview
OpenProdoc OverviewOpenProdoc Overview
OpenProdoc Overview
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
 
Java hibernate orm implementation tool
Java hibernate   orm implementation toolJava hibernate   orm implementation tool
Java hibernate orm implementation tool
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Hibernate

  • 1. CONTENTS 1. Overview 2. Advantages over JDBC 3. Hibernate Architecture 4. Downloading and Installing Hibernate
  • 2. Overview • A popular open source Object Relational Mapping(ORM) tool which provides transparent persistence for POJOS. • ORM is used to map objects to relational databases(Oracle,Mysql). • Allows to map java objects to relational databases and also provides data query • Generates the SQL calls and makes application portable to all SQL databases, with database portability • Allows to develop persistent classes with all java terms – like association, inheritance, polymorphism etc • Can be used as in standalone Java applications or as in Java EE applications using servlets or EJB session beans.
  • 3. Advantages of Hibernate • Retains natural object model (transparent) • Minimizes Code • Does not require a container • Model is not tied to persistence implementation. • Metadata controlled persistence • Transparent - working with the model, not the data access technology • Pooling, Caching, Transactions can be handled outside of our code • Object/relational mappings are defined in an XML document. The mapping document is designed to be readable and hand-editable. • Mapping language is Java-centric, meaning that mappings are constructed around persistent class declarations, not table declarations. • Choose to define XML mappings by hand, or by using tools like XDoclet, Middlegen and AndroMDA.
  • 4.
  • 5.
  • 6. • The “Lite" architecture has the application provide its own JDBC connections and manage its own transactions • Has – SessionFactory – Session – Persistent Objects – Transient Objects • The "full cream" architecture abstracts the application away from the underlying JDBC and Java Transaction API (JTA) and lets Hibernate take care of the details
  • 7.
  • 8. Configuration Configuration class's operation has two key components: • The database connection – handled through one or more configuration files supported by Hibernate – hibernate.properties and hibernate.cfg.xml • The classmapping setup – makes the connection between the Java classes and database tables.
  • 9. 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> <session-factory> <property name="connection.driver"> com.mysql.jdbc.Driver </property> <property name="connection.url“> jdbc:mysql://localhost/products </property> <property name="dialect"> net.sf.hibernate.dialect.MySQLDialect </property> </session-factory> </hibernate-configuration>
  • 10. hibernate.properties hibernate.dialect net.sf.hibernate.dialect.MySQLDialect hibernate.connection.driver_class com.mysql.jdbc.Driver hibernate.connection.url jdbc:mysql://localhost/products hibernate.connection.username root hibernate.connection.password root hibernate.show_sql true hibernate.cglib.use_reflection_optimizer false
  • 11. Hibernate mapping file <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="Notes“ table="notes"> <id name="id" unsaved-value="0"> <generator class="native"/></id> <property name="info" type="string"/> <property name="count" type="integer" not-null="true"/> <property name="zipcode" type="string"/> <property name="fullname" type="string"/> </class></hibernate-mapping>
  • 12. Hibernate Architecture • Basic interfaces used while working with Hibernate are: - SessionFactory - Session - Transaction
  • 13. SessionFactory • A singleton class called SessionFactory is instantiated. • A threadsafe, immutable cache of compiled mappings for a single database. • The SessionFactory object is heavyweight; better to create only one SessionFactory per application. • A factory for creating session objects • Can hold an optional(second-level) cache of data that is reusable between transactions at a process
  • 14. Session • A single-threaded, short-lived object representing a conversation between the application and the persistent store. • is lightweight and instantiated each time an interaction is needed with the database. • As the Session object is created, the objects are persisted or loaded from the database • Then the session object is flushed and closed. • It wraps a JDBC connection and is a factory for Transaction. • Opened by SessionFactory.openSession() • Closed by session.close()
  • 15. ThreadLocal Session Pattern • Use ThreadLocal variable to maintain session data ThreadLocal • Specialized Java class which is associated to a user thread of execution and serves as a data container throughout the lifespan of the thread (or child threads) • Global variable which is local for every thread • To create a thread ThreadLocal sess = new ThreadLocal(); Session session = sess.get(); // to get the current session
  • 16. Transaction • A single-threaded, short-lived object used by the application to specify atomic units of work. • It abstracts the application from the underlying JDBC, JTA or CORBA transaction. • A Session might span several Transactions in some cases. is connected with a concrete session Transaction tx = session.beginTransaction( );
  • 17. Persistent objects and collections(Entities) • Short-lived, single threaded objects containing persistent state and business function. • Can be ordinary JavaBeans/POJOs. • associated with exactly one Session. Transient and detached objects and collections • Instances of persistent classes that are not currently associated with a Session. • Might have been instantiated by the application and not yet persisted • Might have been instantiated by a closed Session.
  • 18. Hibernate Callbacks • public Boolean onSave(Session s); - called before the object is saved to the • database • public Boolean onUpdate(Session s); - called before the object is updated • public boolean onDelete(Session s); - called before the object is deleted • public Boolean onLoad(Session s); - called after the object is loaded from • the database
  • 19. Downloading and Installing Downloading • Download Hibernate from the site (ie) from JBoss tools as Zip • Extract the files to your preferred location • Has 2 folders – plugins and features Adding to Eclipse • Add the files within hibernate /features folder to eclipse/features folder • Add the files within hibernate /plugins folder to eclipse/plugins folder Alternate Way • Open eclipse Help  Update site add hibernate from site

Editor's Notes

  1. Dirty checking Hibernate allows dirty checking feature.All persistent objects are monitored by hibernate.it detects which objects have been modified and then calls update statements on all updated objects.the process of updating the changed object is called automatic dirty checking. Dirty checking allows the user or developer to avoid the time consuming databases write actions. This feature makes necessary updations and changes to the fields which require a change, remaining fields are left unchanged or untouched.