SlideShare ist ein Scribd-Unternehmen logo
1 von 4
HIBERNATE
“Hibernate” is an object-relational mapping (ORM) library for the Java language, providing
a framework for mapping an object oriented domain model to a traditional relational
database.
Hibernate solves object-relational impedance mismatch problems by replacing direct
persistence-related database accesses with high-level object handling functions.
Hibernate is free software that is distributed under the GNU Lesser General Public License.

 What is ORM?
ORM stands for Object-Relational Mapping (ORM) is a programming technique for
converting data between relational databases and object oriented programming languages
such as Java, C# etc.


Java ORM Framework: There are several persistent frameworks and ORM options
in Java. A persistent framework is an ORM service that stores and retrieves objects into a
relational database.
Enterprise JavaBeans Entity Beans
Java Data Objects
Castor
TopLink
Spring DAO etc..,

 Hibernate Installation/Setup on Eclipse IDE
You should download the latest production release of Hibernate from the Hibernate website
at http://www.hibernate.org/ and unpack the archive after download.
Create a new Java Project and enter Hibernate Application as project name.
Create lib and src subdirectories in this project.
Copy JAR files which are listed below, from hibernate distribution that you have
downloaded to the lib directory of the “Hibernate Application” project.
Under root directory of the hibernate distribution: hibernate3.jar
Under lib/required directory of the hibernate distribution:
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar

www.p2cinfotech.com

+1-732-546-3607
HIBERNATE
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-1.6.1.jar
Under lib/jpa directory of the hibernate distribution: hibernate-jpa-2.0-api-1.0.1.Final.jar
Download slf4j-1.6.1.zip file from http://www.slf4j.org/download.html, unpack the archive
and copy the slf4j-simple-1.6.1.jar file to lib directory of the “Hibernate Application” project.
slf4j-simple-1.6.1.jar

 Connecting To Database
you will need the database driver JAR that Hibernate uses to connect to your database.
I use Oracle Express Edition (Oracle XE) and it’s database driver jar is here on Windows:
C:oraclexeapporacleproduct10.2.0serverjdbclibojdbc14.jar
Copy this ojdbc14.jar to the lib directory of the “Hibernate Application” project.
create a User library on Eclipse IDE. Then, I will add all JAR files in the Hibernate
Applicationlib directory to this User library and add this User library to the project build
path.
Click Window–>Preferences on the top menu bar of Eclipse.
Click Java–>Build Path–>User Libraries and click New button then enter “Hibernate”
as the User library name.
Select “Hibernate” User library that we just created and click Add JARS button.
Select all JAR files in the lib folder of the “Hibernate Application” project and click Open
button to add all JAR files to “Hibernate” User library.
Now “Hibernate” User library is ready and we can add this User library to “Hibernate
Application” project build path.
Right click to “Hibernate Application” project and click Build Path–>Add Libraries
Then, select “User Library” and click Next button.
Finally, select “Hibernate” User library and click Finish button.
You have successfully installed Hibernate on Eclipse IDE.



Hibernate caching:
Caching is all about application performance optimization and it sits between your
application and the database to avoid the number of database hits as many as possible to
give a better performance for performance critical applications.
Caching is important to Hibernate as well which utilizes a multilevel caching schemes.

www.p2cinfotech.com

+1-732-546-3607
HIBERNATE

First-level cache: The first-level cache is the Session cache and is a mandatory cache through
which all requests must pass. The Session object keeps an object under its own power before
committing it to the database.
If you issue multiple updates to an object, Hibernate tries to delay doing the update as long as
possible to reduce the number of update SQL statements issued. If you close the session, all the
objects being cached are lost and either persisted or updated in the database.
Second-level cache: Second level cache is an optional cache and first-level cache will always be
consulted before any attempt is made to locate an object in the second-level cache. The secondlevel cache can be configured on a per-class and per-collection basis and mainly responsible for
caching objects across sessions.
Any third-party cache can be used with Hibernate. An org.hibernate.cache.CacheProvider
interface is provided, which must be implemented to provide Hibernate with a handle to the
cache implementation.
Query-level cache: Hibernate also implements a cache for query resultsets that integrates
closely with the second-level cache.
This is an optional feature and requires two additional physical cache regions that hold the
cached query results and the timestamps when a table was last updated. This is only useful for
queries that are run frequently with the same parameters.
The Second Level Cache: Hibernate uses first-level cache by default and you have nothing to
do to use first-level cache. Let's go straight to the optional second-level cache. Not all classes
benefit from caching, so it's important to be able to disable the second-level cache.
The Hibernate second-level cache is set up in two steps. First, you have to decide which
concurrency strategy to use. After that, you configure cache expiration and physical cache
attributes using the cache provider.
Concurrency strategies: A concurrency strategy is a mediator which responsible for storing
items of data in the cache and retrieving them from the cache. If you are going to enable a
second-level cache, you will have to decide, for each persistent class and collection, which cache
concurrency strategy to use.
 Transactional: Use this strategy for read-mostly data where it is critical to
prevent stale data in concurrent transactions,in the rare case of an update.

www.p2cinfotech.com

+1-732-546-3607
HIBERNATE




Read-write: Again use this strategy for read-mostly data where it is critical to
prevent stale data in concurrent transactions,in the rare case of an update.
Nonstrict-read-write: This strategy makes no guarantee of consistency
between the cache and the database. Use this strategy if data hardly ever
changes and a small likelihood of stale data is not of critical concern.
Read-only: A concurrency strategy suitable for data which never changes. Use it
for reference data only.

If we are going to use second-level caching for our Employee class, let us add the mapping element
required to tell Hibernate to cache Employee instances using read-write strategy.

www.p2cinfotech.com

+1-732-546-3607

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (20)

02basics
02basics02basics
02basics
 
Yaazli International Hibernate Training
Yaazli International Hibernate TrainingYaazli International Hibernate Training
Yaazli International Hibernate Training
 
09events
09events09events
09events
 
Non ieee dot net projects list
Non  ieee dot net projects list Non  ieee dot net projects list
Non ieee dot net projects list
 
Core java online training
Core java online trainingCore java online training
Core java online training
 
Savr
SavrSavr
Savr
 
Yaazli International AngularJS 5 Training
Yaazli International AngularJS 5 TrainingYaazli International AngularJS 5 Training
Yaazli International AngularJS 5 Training
 
Toolbarexample
ToolbarexampleToolbarexample
Toolbarexample
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
 
Yaazli International Web Project Workshop
Yaazli International Web Project WorkshopYaazli International Web Project Workshop
Yaazli International Web Project Workshop
 
For Loops and Variables in Java
For Loops and Variables in JavaFor Loops and Variables in Java
For Loops and Variables in Java
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Singleton pattern
Singleton patternSingleton pattern
Singleton pattern
 
DIWE - Using Extensions and Image Manipulation
DIWE - Using Extensions and Image ManipulationDIWE - Using Extensions and Image Manipulation
DIWE - Using Extensions and Image Manipulation
 
Java Basic Operators
Java Basic OperatorsJava Basic Operators
Java Basic Operators
 
Non ieee java projects list
Non  ieee java projects list Non  ieee java projects list
Non ieee java projects list
 
DIWE - Multimedia Technologies
DIWE - Multimedia TechnologiesDIWE - Multimedia Technologies
DIWE - Multimedia Technologies
 
Yaazli International Java Training
Yaazli International Java Training Yaazli International Java Training
Yaazli International Java Training
 
Java notes 1 - operators control-flow
Java notes   1 - operators control-flowJava notes   1 - operators control-flow
Java notes 1 - operators control-flow
 
java swing
java swingjava swing
java swing
 

Mehr von Garuda Trainings

Software development life cycle
Software development life cycleSoftware development life cycle
Software development life cycle
Garuda Trainings
 
Dot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineDot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement online
Garuda Trainings
 

Mehr von Garuda Trainings (11)

Software testing life cycle
Software testing life cycleSoftware testing life cycle
Software testing life cycle
 
Performance testing interview questions and answers
Performance testing interview questions and answersPerformance testing interview questions and answers
Performance testing interview questions and answers
 
Loadrunner interview questions and answers
Loadrunner interview questions and answersLoadrunner interview questions and answers
Loadrunner interview questions and answers
 
Business analysis interview question and answers
Business analysis interview question and answersBusiness analysis interview question and answers
Business analysis interview question and answers
 
Quality center interview questions and answers
Quality center interview questions and answersQuality center interview questions and answers
Quality center interview questions and answers
 
Software development life cycle
Software development life cycleSoftware development life cycle
Software development life cycle
 
Interview Questions and Answers for Java
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for Java
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
 
Dot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement onlineDot net Online Training | .Net Training and Placement online
Dot net Online Training | .Net Training and Placement online
 
Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testing
 
SQL for ETL Testing
SQL for ETL TestingSQL for ETL Testing
SQL for ETL Testing
 

Kürzlich hochgeladen

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
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
heathfieldcps1
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Hibernate Framework

  • 1. HIBERNATE “Hibernate” is an object-relational mapping (ORM) library for the Java language, providing a framework for mapping an object oriented domain model to a traditional relational database. Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions. Hibernate is free software that is distributed under the GNU Lesser General Public License.  What is ORM? ORM stands for Object-Relational Mapping (ORM) is a programming technique for converting data between relational databases and object oriented programming languages such as Java, C# etc.  Java ORM Framework: There are several persistent frameworks and ORM options in Java. A persistent framework is an ORM service that stores and retrieves objects into a relational database. Enterprise JavaBeans Entity Beans Java Data Objects Castor TopLink Spring DAO etc..,  Hibernate Installation/Setup on Eclipse IDE You should download the latest production release of Hibernate from the Hibernate website at http://www.hibernate.org/ and unpack the archive after download. Create a new Java Project and enter Hibernate Application as project name. Create lib and src subdirectories in this project. Copy JAR files which are listed below, from hibernate distribution that you have downloaded to the lib directory of the “Hibernate Application” project. Under root directory of the hibernate distribution: hibernate3.jar Under lib/required directory of the hibernate distribution: antlr-2.7.6.jar commons-collections-3.1.jar dom4j-1.6.1.jar www.p2cinfotech.com +1-732-546-3607
  • 2. HIBERNATE javassist-3.12.0.GA.jar jta-1.1.jar slf4j-api-1.6.1.jar Under lib/jpa directory of the hibernate distribution: hibernate-jpa-2.0-api-1.0.1.Final.jar Download slf4j-1.6.1.zip file from http://www.slf4j.org/download.html, unpack the archive and copy the slf4j-simple-1.6.1.jar file to lib directory of the “Hibernate Application” project. slf4j-simple-1.6.1.jar  Connecting To Database you will need the database driver JAR that Hibernate uses to connect to your database. I use Oracle Express Edition (Oracle XE) and it’s database driver jar is here on Windows: C:oraclexeapporacleproduct10.2.0serverjdbclibojdbc14.jar Copy this ojdbc14.jar to the lib directory of the “Hibernate Application” project. create a User library on Eclipse IDE. Then, I will add all JAR files in the Hibernate Applicationlib directory to this User library and add this User library to the project build path. Click Window–>Preferences on the top menu bar of Eclipse. Click Java–>Build Path–>User Libraries and click New button then enter “Hibernate” as the User library name. Select “Hibernate” User library that we just created and click Add JARS button. Select all JAR files in the lib folder of the “Hibernate Application” project and click Open button to add all JAR files to “Hibernate” User library. Now “Hibernate” User library is ready and we can add this User library to “Hibernate Application” project build path. Right click to “Hibernate Application” project and click Build Path–>Add Libraries Then, select “User Library” and click Next button. Finally, select “Hibernate” User library and click Finish button. You have successfully installed Hibernate on Eclipse IDE.  Hibernate caching: Caching is all about application performance optimization and it sits between your application and the database to avoid the number of database hits as many as possible to give a better performance for performance critical applications. Caching is important to Hibernate as well which utilizes a multilevel caching schemes. www.p2cinfotech.com +1-732-546-3607
  • 3. HIBERNATE First-level cache: The first-level cache is the Session cache and is a mandatory cache through which all requests must pass. The Session object keeps an object under its own power before committing it to the database. If you issue multiple updates to an object, Hibernate tries to delay doing the update as long as possible to reduce the number of update SQL statements issued. If you close the session, all the objects being cached are lost and either persisted or updated in the database. Second-level cache: Second level cache is an optional cache and first-level cache will always be consulted before any attempt is made to locate an object in the second-level cache. The secondlevel cache can be configured on a per-class and per-collection basis and mainly responsible for caching objects across sessions. Any third-party cache can be used with Hibernate. An org.hibernate.cache.CacheProvider interface is provided, which must be implemented to provide Hibernate with a handle to the cache implementation. Query-level cache: Hibernate also implements a cache for query resultsets that integrates closely with the second-level cache. This is an optional feature and requires two additional physical cache regions that hold the cached query results and the timestamps when a table was last updated. This is only useful for queries that are run frequently with the same parameters. The Second Level Cache: Hibernate uses first-level cache by default and you have nothing to do to use first-level cache. Let's go straight to the optional second-level cache. Not all classes benefit from caching, so it's important to be able to disable the second-level cache. The Hibernate second-level cache is set up in two steps. First, you have to decide which concurrency strategy to use. After that, you configure cache expiration and physical cache attributes using the cache provider. Concurrency strategies: A concurrency strategy is a mediator which responsible for storing items of data in the cache and retrieving them from the cache. If you are going to enable a second-level cache, you will have to decide, for each persistent class and collection, which cache concurrency strategy to use.  Transactional: Use this strategy for read-mostly data where it is critical to prevent stale data in concurrent transactions,in the rare case of an update. www.p2cinfotech.com +1-732-546-3607
  • 4. HIBERNATE    Read-write: Again use this strategy for read-mostly data where it is critical to prevent stale data in concurrent transactions,in the rare case of an update. Nonstrict-read-write: This strategy makes no guarantee of consistency between the cache and the database. Use this strategy if data hardly ever changes and a small likelihood of stale data is not of critical concern. Read-only: A concurrency strategy suitable for data which never changes. Use it for reference data only. If we are going to use second-level caching for our Employee class, let us add the mapping element required to tell Hibernate to cache Employee instances using read-write strategy. www.p2cinfotech.com +1-732-546-3607