SlideShare a Scribd company logo
1 of 28
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
By Dinesh Radadiya
Hibernate Basics
By Jainesh Trivedi
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Agenda
2
 Introduction to Hibernate and ORM
 Arcitecture
 Hibernate Configuration
 Annotations, Mappings and HQL
 Cascade
 Caching
 Interceptors
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
3
Introduction
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Introduction
4
 High Performance Object/Relational mapping solution and
queryservice
 Open Source Persistence Framework created by Gavin King in
2001.
 Takes care of mapping of Java datatypes and SQL type.
 It also maps Java classes to the database tables.
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth 55
Introduction
 Programming code that converts data between
database and OO Languages.
 ORM Advantages:-
 Allows business code to acces objects instead of DB
tables.
 Entities based on business structure instead of DB.
 Hides details of SQL queries.
 No need to deal with database implementation.
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth 6
Hibernate Architecture
Hibernate Architecture
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth 7
Hibernate Architecture
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth 8
Hibernate Architecture
● Configuration Object
● SessionFactory Object
● Session Object
● Transaction Object
● Query Object
● Criteria Object
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth 9
Hibernate Architecture
● Criteria criteria =
session.createCriteria(StockDailyRecord.class);
● .addOrder(Order.asc(“date”));
● Restrictions in criteria object:
lt,ge,gt,le,isNull,like,isNotNull,between,etc
● .add(Restrictions.like(“Name”,”Know%”))
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth 10
Hibernate Architecture
● Downloading Hibernate:
– Download the latest version of
Hibernate http://www.hibernate.org/do
wnloads
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
1111
Hibernate Configuration
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Hibernate Configuration
12
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Connection to Oracle db -->
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.connection.username">test</property>
<property name="hibernate.connection.password">test123</property>
<!-- Auto commit to false -->
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
</session-factory>
</hibernate-configuration>
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
1313
Annotations,Mapping and HQL
© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Annotations,Mapping and HQL
14
– One to One
– One to Many
– Many to One
– Many to Many
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Annotations,Mapping and HQL
15
 Powerful tool to define mapping without XML
files,one can use annotations with or as a
replacement to XML files
 Enviornment Setup for annotations:-
● Install Hiberanate 3.X annotations package to
use annoations for mapping.
 @Entity,@Table,@Id,@GeneratedValue,@Column are
some of the basic annoations
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Annotations,Mapping and HQL
16
 Hibernate Query Language is a query language
similar to SQL but operates on objects instead of
table and column
 HQL queries are translated to conventional SQL
queries which inturn perform the operations.
 HQL makes use of persistent objects and their
properties to operate.
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
17
Examples
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Cascade
18
● Cascade is an important feature provided by Hibernate using
which one can manage state of other objects related to a
particular object.
● Its like propogating the change to all the interlinked objects by
just applying the change to the parent object.
● Cascading can be used to easily maintain the consistency but it
should be used wisely inorder to avoid unnecessary cascade
affects.
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Native SQL
19
 Hibernate provides a method createSQL() to make native SQL
statement directly.
 One can use native calls to insert,update,delete and load date
using this and we can use stored procedures.
Query query = session.createSQLQuery(
"select * from stock s where s.stock_code = :stockCode")
.addEntity(Stock.class)
.setParameter("stockCode", "7277");
List result = query.list();
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Caching
20
 Caching is basically used to enhance the system performance
by reducing the number of database hits.
 Hibernate cache sits between the database and your
application.
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Caching
21
First-level cache:
● Always associates with the Session object. Hibernate uses this
cache by default.
● Its easy to understand the first level cache if we understand the fact
that it is associated with Session object.
● When we query an entity first time, it is retrieved from database and
stored in first level cache associated with hibernate session.
● The loaded entity can be removed from session using evict()
method. The next loading of this entity will again make a database
call if it has been removed using evict() method.
● The whole session cache can be removed using clear() method. It
will remove all the entities stored in cache.
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Caching
22
Second-level cache:
● Always associates with sessionFactoryObject and is available to be
● used in all sessions which are created using that particular session
factory.
● 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.
● Any third-party cache can be used with Hibernate.
An org.hibernate.cache.CacheProvider interface is provided
<property name="hibernate.cache.use_second_level_cache">true</property>
<property
name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider
</property>
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Caching
23
To use the query cache, you use the setCacheable(Boolean) method of the
Query class.
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth 24
Interceptors
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth 25
Interceptors
● As we know that in Hibernate, an object will be created and persisted. Once the
object has been changed, it must be saved back to the database.
● Thus the object passed through different stages of life-cycle before been saved,
so interceptors provide methods that can be used to manipulate objects during
the different stages of life cyle.
● These methods are callbacks from the session to the application, allowing the
application to inspect and/or manipulate properties of a persistent object before
it is saved, updated, deleted or loaded.
● To build a custom interceptor one can do it by simply implementing the
Interceptor interface or extend the EmptyInterceptor class.
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth 26
Interceptors
● Methods in interceptors
© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
© 2013 Knowarth
Query & Questions
27© 2015 KNOWARTH
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
THANK YOU
© 2015 KNOWARTH

More Related Content

Viewers also liked

Viewers also liked (13)

NodeJS - KNOWARTH
NodeJS - KNOWARTHNodeJS - KNOWARTH
NodeJS - KNOWARTH
 
Web Framework and Struts 2 - KNOWARTH
Web Framework and Struts 2 - KNOWARTHWeb Framework and Struts 2 - KNOWARTH
Web Framework and Struts 2 - KNOWARTH
 
Java 8 - KNOWARTH
Java 8 - KNOWARTHJava 8 - KNOWARTH
Java 8 - KNOWARTH
 
Bootstrap - KNOWARTH
Bootstrap - KNOWARTHBootstrap - KNOWARTH
Bootstrap - KNOWARTH
 
MongoDB - KNOWARTH
MongoDB - KNOWARTHMongoDB - KNOWARTH
MongoDB - KNOWARTH
 
Presentacion de blacbord
Presentacion de blacbordPresentacion de blacbord
Presentacion de blacbord
 
Basics of Spring - KNOWARTH
Basics of Spring - KNOWARTHBasics of Spring - KNOWARTH
Basics of Spring - KNOWARTH
 
Angular JS - KNOWARTH
Angular JS - KNOWARTHAngular JS - KNOWARTH
Angular JS - KNOWARTH
 
Introduction to Magento - KNOWARTH
Introduction to Magento - KNOWARTHIntroduction to Magento - KNOWARTH
Introduction to Magento - KNOWARTH
 
Green movement 2012 candidate review
Green movement 2012 candidate reviewGreen movement 2012 candidate review
Green movement 2012 candidate review
 
VMWare based Cloud Computing - KNOWARTH
VMWare based Cloud Computing - KNOWARTHVMWare based Cloud Computing - KNOWARTH
VMWare based Cloud Computing - KNOWARTH
 
Swimming Pool Design
Swimming Pool DesignSwimming Pool Design
Swimming Pool Design
 
Mechanical analysis of soil
Mechanical analysis of soilMechanical analysis of soil
Mechanical analysis of soil
 

Similar to Hibernate - KNOWARTH

Cassandra Day Atlanta 2015: BetterCloud: Leveraging Apache Cassandra
Cassandra Day Atlanta 2015: BetterCloud: Leveraging Apache CassandraCassandra Day Atlanta 2015: BetterCloud: Leveraging Apache Cassandra
Cassandra Day Atlanta 2015: BetterCloud: Leveraging Apache CassandraDataStax Academy
 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.Luigi Viggiano
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Trainingsourabh aggarwal
 
Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Anne Tomasevich
 
Apache - Mod-Rewrite
Apache - Mod-RewriteApache - Mod-Rewrite
Apache - Mod-RewriteMarakana Inc.
 
Obevo Javasig.pptx
Obevo Javasig.pptxObevo Javasig.pptx
Obevo Javasig.pptxLadduAnanu
 
Dsc Charusat Learning React Part 1
Dsc Charusat Learning React Part 1 Dsc Charusat Learning React Part 1
Dsc Charusat Learning React Part 1 JainamMehta19
 
Adam Sanyo - Conref, conkeyref, conrefpush: Reuse strategies when working on ...
Adam Sanyo - Conref, conkeyref, conrefpush: Reuse strategies when working on ...Adam Sanyo - Conref, conkeyref, conrefpush: Reuse strategies when working on ...
Adam Sanyo - Conref, conkeyref, conrefpush: Reuse strategies when working on ...soapconf
 
"Conref, conkeyref, conrefpush" - reuse strategies in DITA when migrating leg...
"Conref, conkeyref, conrefpush" - reuse strategies in DITA when migrating leg..."Conref, conkeyref, conrefpush" - reuse strategies in DITA when migrating leg...
"Conref, conkeyref, conrefpush" - reuse strategies in DITA when migrating leg...Adam Sanyo
 
Hazelcast Essentials
Hazelcast EssentialsHazelcast Essentials
Hazelcast EssentialsRahul Gupta
 
Ultimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on KubernetesUltimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on Kuberneteskloia
 

Similar to Hibernate - KNOWARTH (20)

Hibernate 1x2
Hibernate 1x2Hibernate 1x2
Hibernate 1x2
 
Cassandra Day Atlanta 2015: BetterCloud: Leveraging Apache Cassandra
Cassandra Day Atlanta 2015: BetterCloud: Leveraging Apache CassandraCassandra Day Atlanta 2015: BetterCloud: Leveraging Apache Cassandra
Cassandra Day Atlanta 2015: BetterCloud: Leveraging Apache Cassandra
 
Html5 tutorial
Html5 tutorialHtml5 tutorial
Html5 tutorial
 
Html5 - Tutorial
Html5 - TutorialHtml5 - Tutorial
Html5 - Tutorial
 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
Doc store
Doc storeDoc store
Doc store
 
Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8
 
Apache - Mod-Rewrite
Apache - Mod-RewriteApache - Mod-Rewrite
Apache - Mod-Rewrite
 
Obevo Javasig.pptx
Obevo Javasig.pptxObevo Javasig.pptx
Obevo Javasig.pptx
 
Dsc Charusat Learning React Part 1
Dsc Charusat Learning React Part 1 Dsc Charusat Learning React Part 1
Dsc Charusat Learning React Part 1
 
Adam Sanyo - Conref, conkeyref, conrefpush: Reuse strategies when working on ...
Adam Sanyo - Conref, conkeyref, conrefpush: Reuse strategies when working on ...Adam Sanyo - Conref, conkeyref, conrefpush: Reuse strategies when working on ...
Adam Sanyo - Conref, conkeyref, conrefpush: Reuse strategies when working on ...
 
"Conref, conkeyref, conrefpush" - reuse strategies in DITA when migrating leg...
"Conref, conkeyref, conrefpush" - reuse strategies in DITA when migrating leg..."Conref, conkeyref, conrefpush" - reuse strategies in DITA when migrating leg...
"Conref, conkeyref, conrefpush" - reuse strategies in DITA when migrating leg...
 
Html5 tutorial
Html5 tutorialHtml5 tutorial
Html5 tutorial
 
Html5 tutorial
Html5 tutorialHtml5 tutorial
Html5 tutorial
 
Html5 tutorial
Html5 tutorialHtml5 tutorial
Html5 tutorial
 
Html5 tutorial
Html5 tutorialHtml5 tutorial
Html5 tutorial
 
Html5 tutorial
Html5 tutorialHtml5 tutorial
Html5 tutorial
 
Hazelcast Essentials
Hazelcast EssentialsHazelcast Essentials
Hazelcast Essentials
 
Ultimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on KubernetesUltimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on Kubernetes
 

Recently uploaded

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
[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
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[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
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Hibernate - KNOWARTH

  • 1. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level By Dinesh Radadiya Hibernate Basics By Jainesh Trivedi © 2015 KNOWARTH
  • 2. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Agenda 2  Introduction to Hibernate and ORM  Arcitecture  Hibernate Configuration  Annotations, Mappings and HQL  Cascade  Caching  Interceptors © 2015 KNOWARTH
  • 3. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 3 Introduction © 2015 KNOWARTH
  • 4. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Introduction 4  High Performance Object/Relational mapping solution and queryservice  Open Source Persistence Framework created by Gavin King in 2001.  Takes care of mapping of Java datatypes and SQL type.  It also maps Java classes to the database tables. © 2015 KNOWARTH
  • 5. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth 55 Introduction  Programming code that converts data between database and OO Languages.  ORM Advantages:-  Allows business code to acces objects instead of DB tables.  Entities based on business structure instead of DB.  Hides details of SQL queries.  No need to deal with database implementation. © 2015 KNOWARTH
  • 6. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth 6 Hibernate Architecture Hibernate Architecture © 2015 KNOWARTH
  • 7. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth 7 Hibernate Architecture © 2015 KNOWARTH
  • 8. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth 8 Hibernate Architecture ● Configuration Object ● SessionFactory Object ● Session Object ● Transaction Object ● Query Object ● Criteria Object © 2015 KNOWARTH
  • 9. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth 9 Hibernate Architecture ● Criteria criteria = session.createCriteria(StockDailyRecord.class); ● .addOrder(Order.asc(“date”)); ● Restrictions in criteria object: lt,ge,gt,le,isNull,like,isNotNull,between,etc ● .add(Restrictions.like(“Name”,”Know%”)) © 2015 KNOWARTH
  • 10. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth 10 Hibernate Architecture ● Downloading Hibernate: – Download the latest version of Hibernate http://www.hibernate.org/do wnloads © 2015 KNOWARTH
  • 11. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 1111 Hibernate Configuration © 2015 KNOWARTH
  • 12. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Hibernate Configuration 12 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Connection to Oracle db --> <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property> <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> <property name="hibernate.connection.username">test</property> <property name="hibernate.connection.password">test123</property> <!-- Auto commit to false --> <property name="hibernate.connection.autocommit">false</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">true</property> <property name="hibernate.use_sql_comments">true</property> </session-factory> </hibernate-configuration> © 2015 KNOWARTH
  • 13. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 1313 Annotations,Mapping and HQL © 2014 Knowarth
  • 14. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Annotations,Mapping and HQL 14 – One to One – One to Many – Many to One – Many to Many © 2015 KNOWARTH
  • 15. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Annotations,Mapping and HQL 15  Powerful tool to define mapping without XML files,one can use annotations with or as a replacement to XML files  Enviornment Setup for annotations:- ● Install Hiberanate 3.X annotations package to use annoations for mapping.  @Entity,@Table,@Id,@GeneratedValue,@Column are some of the basic annoations © 2015 KNOWARTH
  • 16. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Annotations,Mapping and HQL 16  Hibernate Query Language is a query language similar to SQL but operates on objects instead of table and column  HQL queries are translated to conventional SQL queries which inturn perform the operations.  HQL makes use of persistent objects and their properties to operate.
  • 17. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 17 Examples © 2015 KNOWARTH
  • 18. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Cascade 18 ● Cascade is an important feature provided by Hibernate using which one can manage state of other objects related to a particular object. ● Its like propogating the change to all the interlinked objects by just applying the change to the parent object. ● Cascading can be used to easily maintain the consistency but it should be used wisely inorder to avoid unnecessary cascade affects. © 2015 KNOWARTH
  • 19. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Native SQL 19  Hibernate provides a method createSQL() to make native SQL statement directly.  One can use native calls to insert,update,delete and load date using this and we can use stored procedures. Query query = session.createSQLQuery( "select * from stock s where s.stock_code = :stockCode") .addEntity(Stock.class) .setParameter("stockCode", "7277"); List result = query.list(); © 2015 KNOWARTH
  • 20. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Caching 20  Caching is basically used to enhance the system performance by reducing the number of database hits.  Hibernate cache sits between the database and your application. © 2015 KNOWARTH
  • 21. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Caching 21 First-level cache: ● Always associates with the Session object. Hibernate uses this cache by default. ● Its easy to understand the first level cache if we understand the fact that it is associated with Session object. ● When we query an entity first time, it is retrieved from database and stored in first level cache associated with hibernate session. ● The loaded entity can be removed from session using evict() method. The next loading of this entity will again make a database call if it has been removed using evict() method. ● The whole session cache can be removed using clear() method. It will remove all the entities stored in cache. © 2015 KNOWARTH
  • 22. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Caching 22 Second-level cache: ● Always associates with sessionFactoryObject and is available to be ● used in all sessions which are created using that particular session factory. ● 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. ● Any third-party cache can be used with Hibernate. An org.hibernate.cache.CacheProvider interface is provided <property name="hibernate.cache.use_second_level_cache">true</property> <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider </property>
  • 23. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Caching 23 To use the query cache, you use the setCacheable(Boolean) method of the Query class. © 2015 KNOWARTH
  • 24. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth 24 Interceptors © 2015 KNOWARTH
  • 25. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth 25 Interceptors ● As we know that in Hibernate, an object will be created and persisted. Once the object has been changed, it must be saved back to the database. ● Thus the object passed through different stages of life-cycle before been saved, so interceptors provide methods that can be used to manipulate objects during the different stages of life cyle. ● These methods are callbacks from the session to the application, allowing the application to inspect and/or manipulate properties of a persistent object before it is saved, updated, deleted or loaded. ● To build a custom interceptor one can do it by simply implementing the Interceptor interface or extend the EmptyInterceptor class. © 2015 KNOWARTH
  • 26. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth 26 Interceptors ● Methods in interceptors © 2015 KNOWARTH
  • 27. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level © 2013 Knowarth Query & Questions 27© 2015 KNOWARTH
  • 28. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level THANK YOU © 2015 KNOWARTH

Editor's Notes

  1. Purpose of MVC is separate out each layer so application become easily scalable For example you want to change look of your application only view gets impacted if all 3 layers are properly seperated