SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
Hibernate Framework
What is ORM ?
● ORM handles object relational impedance mis-match .
● Relational Database is table driven (with rows and column) for fast query operation
whereas java code is made up with object and classes of this is mis-match in
between java code and relational database .
● Like there is different tend to define data e.g for numeric value NUMBER in oracle
● ORM handles this mis-match for you.
● If you are not using any ORM tool so you have to do all these mapping and for large
application it could be complex .
What is Hibernate ?
● Hibernate is most popular ORM framework and it and it let you work without being constrained
by table driven relational database model .
● Is handles relational mis-match.
● And in addition to its own native API hibernate also implements JPA API specification . As
such it can be use in any environment .
● You do not need to work with JDBC .
● So the core of hibernate is all about making persisting data easier .
Architecture
● The following diagram describe high level
architecture of hibernate
● In this diagram the hibernate is using
Persistence.xml file for the configuration.
● And at the bottom there is Database which
is managed by hibernate connection
manager.
● Database is most expensive part because
it require lots of resource to open and
close connection.
Persistence.xml file
● Its standard configuration file in JPA it has to be include in the
META-INF folder in class directory .
● This file specify that which underline database is suppose to save,
update and remove the entity objects .
● This file configure for cache.
● This file configure for object relational mapping .
Example
1. <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
2. <persistence-unit name="infinite">
3. <provider>org.hibernate.ejb.HibernatePersistence</provider>
4. <properties>
5. <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
6. <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
7. <property name="hibernate.connection.username" value="SRT3"/>
8. <property name="hibernate.connection.password" value="adept"/>
9. <property name="hibernate.connection.url" value="jdbc:oracle:thin:@//v-in-windmill-db-m:1521/optymyze"/>
10. <property name="hibernate.format_sql" value="true"/>
11. <property name="hibernate.hbm2ddl.auto" value="update"/>
12. </properties>
13. </persistence-unit>
14. </persistence>
Domain class
● Domain classes are class in an application that implement the entity of business
domain.
● An entity is a plain old java object (POJO) and formally it also called as entity
bean .
● This class represents a table in the database and instance represents row in that
table.
● Requirements
○ Annotation with the javax.persistence.Entity annotation
○ Public or protected non argument constructor
○ The class must not be declare final
○ No instance must not be declare final .
Persistence Context
● Persistence context is the set of managed
objects of entity manager that exist in
particular data store.
● At runtime whenever a session is opened and
closed, between those open and close
boundaries Hibernate maintains the object in a
Persistence Context. Think of it like a first level
runtime cache which hibernate controls.
● If an object that has to be retrieved and already
exists in the persistence context, the existing
managed object is returned without actually
accessing the database
Instance States
● An instance of the domain class that means domain object can be in one of three states like .
1. Transient state
2. Persistence state
3. Removed state
4. Detached state
Operations
● Saving Objects
○ It’s most common operation that we perform in hibernate
○ By using persist method we can save objects.
● Retrieving objects
○ When we working with any sort of ORM or persistence framework we always need to return entity from the
database it can be list or a single entity .
○ So we gonna look how we do it with JPA.
● Updating Object
○ Here we see that how to modify persisted instance.
Count..
● Removing Objects
○ Here we remove entity from Database so for that in EntityManager we have remove method by
calling .
Entity Association
When we build an application we are not only writing data to a single table within a data model ,
entities are related to each other in different ways.
Following are the four ways in which the cardinality of the relationship between the
objects can be expressed. An association mapping can be unidirectional as well as
bidirectional.
1. One-To-One
2. One-To-Many
3. Many-to-One
4. Many-To-Many
One-To-One
→ A one-to-one relationships occurs when one entity is related to exactly one occurrence in another entity.
→ In this relationship, one object of the one pojo class contains association with one object of the another
pojo class.
This relationship is supposing a user has only one credential.The navigation is one-way from the credential to the user : it’s possible to know
Credential of a User, but not vice-versa.
One-To-Many
→ A one-to-many association is the most common kind of association where an Object can be associated with
multiple objects. For example a same Department object can be associated with multiple employee objects.
→ If the persistent class has list object that contains the entity reference, we need to use one-to-many association to map the
list element.
Employee and Department table hold One-to-many relationship. Each Department can be associated with
multiple Employees and each Employee can have only one Department.
Many-To-Many
→ A logical data relationship in which the value of one data element can exist in combination with many values of another
data element, and vice versa.
A many-to-many relationship refers to a relationship between tables in a database when a parent row in one table contains
several child rows in the second table, and vice versa.
→ We are using Employee-Meeting relationship as a many to many relationship example. Each Employee
can attain more than one meetings and each meetings can have more than one employee
Entity Inheritance
→ Java is an object oriented language and It is possible to implement Inheritance in java and which one of
the most visible Object-relational mismatch in Relational model. Object oriented systems can model both “is a”
and “has a” relationship but Relational model supports only “has a” relationship between two entities.
Hibernate can help you to map such Objects with relational tables. But we need to choose certain mapping
strategy based on your needs.
There are three types of inheritance mapping in hibernate
1. Table per concrete class
2. Table per class hierarchy(Single Table Strategy)
3. Table per subclass
Table Per Class Hierarchy
In One Table per Class Hierarchy scheme, we store all the class hierarchy in a single table. A discriminator is
a key to uniquely identify the base type of the class hierarchy.
Following are the advantages and disadvantages of One Table per Class Hierarchy scheme.
Advantage
● This hierarchy offers the best performance since single select may suffice.
● Only one table to deal with.
● Performance wise better than all strategies because no joins need to be performed.
.
Advantage/Disadvantage
Disadvantage
● Changes to members of the hierarchy required column to be altered, added or removed from the table.
● Most of the column of table are nullable so the NOT NULL constraint cannot be applied.
● Tables are not normalized.
One Table per Concrete Class
In case of Table Per Concrete class, tables are created per class and there are no
nullable values in the table. Disadvantage of this approach is that duplicate
columns are created in the subclass tables.
In this case let's say our Person class is abstract and Employee and Owner are concrete classes. So the table
structure that comes out is basically one table for Owner and one table for Employee. The data for Person is
duplicated in both the tables.
Following are the advantages and disadvantages of One Table per Subclass scheme
Advantages
This is the easiest method of Inheritance mapping to implement.
● Possible to define NOT NULL constraints on the table.
Disadvantages
● Disadvantage of this approach is that duplicate columns are created in the sub tables.
● Changes to a parent class is reflected to large number of tables
● Tables are not normalized.
One Table Per Subclass
Suppose we have a class Person with subclass Employee and Owner. Following the class diagram and
relationship of these classes.
In One Table per Subclass scheme, each class persist the data in its own separate table. Thus in this one we have 3 tables;
PERSON, EMPLOYEE and OWNER to persist the class data. But a foreign key relationship exists between the sub class
tables and superclass table. So the common data is stored in PERSON table and subclass specific fields are stored in
EMPLOYEE and OWNER tables.
Advantage/Disadvantage
Advantage
● Tables are normalized.
● Able to define NOT NULL constraint.
● It works well with shallow hierarchy.
Disadvantage
● As the hierarchy grows, it may result in poor performance.
Caching
Caching is all about application performance optimization and it exists 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.
Hibernate second level cache uses a common cache for all the entityManager object of an Entity Manager Factory. It is useful
if you have multiple session objects from a session factory.
EntityManagerFactory holds the second level cache data. It is global for all the session objects and not enabled by default.

Weitere ähnliche Inhalte

Was ist angesagt?

Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming TechniquesRaji Ghawi
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An IntroductionNguyen Cao
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate TutorialRam132
 
Hibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examplesHibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examplesEr. Gaurav Kumar
 
Spring (1)
Spring (1)Spring (1)
Spring (1)Aneega
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP conceptsAhmed Farag
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernatehr1383
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Sakthi Durai
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 

Was ist angesagt? (20)

Hibernate
HibernateHibernate
Hibernate
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Hibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examplesHibernate inheritance and relational mappings with examples
Hibernate inheritance and relational mappings with examples
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
Jpa
JpaJpa
Jpa
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Hibernate in Nutshell
Hibernate in NutshellHibernate in Nutshell
Hibernate in Nutshell
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Hibernate
HibernateHibernate
Hibernate
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
 
JavaEE Spring Seam
JavaEE Spring SeamJavaEE Spring Seam
JavaEE Spring Seam
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Java beans
Java beansJava beans
Java beans
 

Andere mochten auch

Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Patrycja Wegrzynowicz
 
Secure Authentication and Session Management in Java EE
Secure Authentication and Session Management in Java EESecure Authentication and Session Management in Java EE
Secure Authentication and Session Management in Java EEPatrycja Wegrzynowicz
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your developmentStrannik_2013
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring DataArturs Drozdovs
 
Spring.Boot up your development
Spring.Boot up your developmentSpring.Boot up your development
Spring.Boot up your developmentStrannik_2013
 
Amazon Webservices for Java Developers - UCI Webinar
Amazon Webservices for Java Developers - UCI WebinarAmazon Webservices for Java Developers - UCI Webinar
Amazon Webservices for Java Developers - UCI WebinarCraig Dickson
 
Junior,middle,senior?
Junior,middle,senior?Junior,middle,senior?
Junior,middle,senior?Strannik_2013
 
Java Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewJava Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewCraig Dickson
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewBrett Meyer
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCdigitalsonic
 

Andere mochten auch (20)

Thinking Beyond ORM in JPA
Thinking Beyond ORM in JPAThinking Beyond ORM in JPA
Thinking Beyond ORM in JPA
 
Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
Secure Authentication and Session Management in Java EE
Secure Authentication and Session Management in Java EESecure Authentication and Session Management in Java EE
Secure Authentication and Session Management in Java EE
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your development
 
Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 
JPA For Beginner's
JPA For Beginner'sJPA For Beginner's
JPA For Beginner's
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
JPA - Beyond copy-paste
JPA - Beyond copy-pasteJPA - Beyond copy-paste
JPA - Beyond copy-paste
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
Spring.Boot up your development
Spring.Boot up your developmentSpring.Boot up your development
Spring.Boot up your development
 
Spring
SpringSpring
Spring
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Spring Data Jpa
Spring Data JpaSpring Data Jpa
Spring Data Jpa
 
Amazon Webservices for Java Developers - UCI Webinar
Amazon Webservices for Java Developers - UCI WebinarAmazon Webservices for Java Developers - UCI Webinar
Amazon Webservices for Java Developers - UCI Webinar
 
Junior,middle,senior?
Junior,middle,senior?Junior,middle,senior?
Junior,middle,senior?
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
 
Java Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewJava Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief Overview
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVC
 

Ähnlich wie Hibernate using jpa

Object relationship mapping and hibernate
Object relationship mapping and hibernateObject relationship mapping and hibernate
Object relationship mapping and hibernateJoe Jacob
 
SQL Tutorial - Basics of Structured Query Language Day 1.pdf
SQL Tutorial - Basics of Structured Query Language Day 1.pdfSQL Tutorial - Basics of Structured Query Language Day 1.pdf
SQL Tutorial - Basics of Structured Query Language Day 1.pdfRiturajDas28
 
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.pptMODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.pptHemaSenthil5
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemNishant Munjal
 
Ibps it officer exam capsule by affairs cloud
Ibps it officer exam capsule by affairs cloudIbps it officer exam capsule by affairs cloud
Ibps it officer exam capsule by affairs cloudaffairs cloud
 
Ibps it officer exam capsule by affairs cloud
Ibps it officer exam capsule by affairs cloudIbps it officer exam capsule by affairs cloud
Ibps it officer exam capsule by affairs cloudaffairs cloud
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxKoteswari Kasireddy
 
Mapping objects to_relational_databases
Mapping objects to_relational_databasesMapping objects to_relational_databases
Mapping objects to_relational_databasesIvan Paredes
 
MODULE 3 -Normalization_1.ppt moduled in design
MODULE 3 -Normalization_1.ppt moduled in designMODULE 3 -Normalization_1.ppt moduled in design
MODULE 3 -Normalization_1.ppt moduled in designHemaSenthil5
 
Interview questions(programming)
Interview questions(programming)Interview questions(programming)
Interview questions(programming)sunilbhaisora1
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answersLakshmiSarvani6
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemNishant Munjal
 
database management system - overview of entire dbms
database management system - overview of entire dbmsdatabase management system - overview of entire dbms
database management system - overview of entire dbmsvikramkagitapu
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemSelshaCs
 
DBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdfDBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)Zhang Bo
 
object oriented analysis data.pptx
object oriented analysis data.pptxobject oriented analysis data.pptx
object oriented analysis data.pptxnibiganesh
 

Ähnlich wie Hibernate using jpa (20)

Object relationship mapping and hibernate
Object relationship mapping and hibernateObject relationship mapping and hibernate
Object relationship mapping and hibernate
 
Data Structures & Algorithms
Data Structures & AlgorithmsData Structures & Algorithms
Data Structures & Algorithms
 
SQL Tutorial - Basics of Structured Query Language Day 1.pdf
SQL Tutorial - Basics of Structured Query Language Day 1.pdfSQL Tutorial - Basics of Structured Query Language Day 1.pdf
SQL Tutorial - Basics of Structured Query Language Day 1.pdf
 
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.pptMODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Ibps it officer exam capsule by affairs cloud
Ibps it officer exam capsule by affairs cloudIbps it officer exam capsule by affairs cloud
Ibps it officer exam capsule by affairs cloud
 
Ibps it officer exam capsule by affairs cloud
Ibps it officer exam capsule by affairs cloudIbps it officer exam capsule by affairs cloud
Ibps it officer exam capsule by affairs cloud
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptx
 
Mapping objects to_relational_databases
Mapping objects to_relational_databasesMapping objects to_relational_databases
Mapping objects to_relational_databases
 
MODULE 3 -Normalization_1.ppt moduled in design
MODULE 3 -Normalization_1.ppt moduled in designMODULE 3 -Normalization_1.ppt moduled in design
MODULE 3 -Normalization_1.ppt moduled in design
 
Interview questions(programming)
Interview questions(programming)Interview questions(programming)
Interview questions(programming)
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
database management system - overview of entire dbms
database management system - overview of entire dbmsdatabase management system - overview of entire dbms
database management system - overview of entire dbms
 
Unit 2 DBMS.pptx
Unit 2 DBMS.pptxUnit 2 DBMS.pptx
Unit 2 DBMS.pptx
 
DBMS unit 1.pptx
DBMS unit 1.pptxDBMS unit 1.pptx
DBMS unit 1.pptx
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
DBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdfDBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdf
 
Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)
 
object oriented analysis data.pptx
object oriented analysis data.pptxobject oriented analysis data.pptx
object oriented analysis data.pptx
 

Mehr von Mohammad Faizan

Mehr von Mohammad Faizan (16)

Jdbc basic features
Jdbc basic featuresJdbc basic features
Jdbc basic features
 
Tutorial c#
Tutorial c#Tutorial c#
Tutorial c#
 
Java 8 from perm gen to metaspace
Java 8  from perm gen to metaspaceJava 8  from perm gen to metaspace
Java 8 from perm gen to metaspace
 
SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4  SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4
 
Software maintenance Unit5
Software maintenance  Unit5Software maintenance  Unit5
Software maintenance Unit5
 
Jvm internal detail
Jvm internal detailJvm internal detail
Jvm internal detail
 
Unit3 Software engineering UPTU
Unit3 Software engineering UPTUUnit3 Software engineering UPTU
Unit3 Software engineering UPTU
 
Unit2 Software engineering UPTU
Unit2 Software engineering UPTUUnit2 Software engineering UPTU
Unit2 Software engineering UPTU
 
Allama Iqbal shiqwa with meaning
Allama Iqbal shiqwa with meaningAllama Iqbal shiqwa with meaning
Allama Iqbal shiqwa with meaning
 
Web tech chapter 1 (1)
Web tech chapter 1 (1)Web tech chapter 1 (1)
Web tech chapter 1 (1)
 
Mdm intro-chapter1
Mdm intro-chapter1Mdm intro-chapter1
Mdm intro-chapter1
 
Hill climbing
Hill climbingHill climbing
Hill climbing
 
Coda file system tahir
Coda file system   tahirCoda file system   tahir
Coda file system tahir
 
Chapter30 (1)
Chapter30 (1)Chapter30 (1)
Chapter30 (1)
 
Ai4 heuristic2
Ai4 heuristic2Ai4 heuristic2
Ai4 heuristic2
 
Chapter30
Chapter30Chapter30
Chapter30
 

Kürzlich hochgeladen

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
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 ConsultingTechSoup
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
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 SectorsAssociation for Project Management
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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.pdfAdmir Softic
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Kürzlich hochgeladen (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 
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
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
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
 
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"
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Hibernate using jpa

  • 2. What is ORM ? ● ORM handles object relational impedance mis-match . ● Relational Database is table driven (with rows and column) for fast query operation whereas java code is made up with object and classes of this is mis-match in between java code and relational database . ● Like there is different tend to define data e.g for numeric value NUMBER in oracle ● ORM handles this mis-match for you. ● If you are not using any ORM tool so you have to do all these mapping and for large application it could be complex .
  • 3. What is Hibernate ? ● Hibernate is most popular ORM framework and it and it let you work without being constrained by table driven relational database model . ● Is handles relational mis-match. ● And in addition to its own native API hibernate also implements JPA API specification . As such it can be use in any environment . ● You do not need to work with JDBC . ● So the core of hibernate is all about making persisting data easier .
  • 4. Architecture ● The following diagram describe high level architecture of hibernate ● In this diagram the hibernate is using Persistence.xml file for the configuration. ● And at the bottom there is Database which is managed by hibernate connection manager. ● Database is most expensive part because it require lots of resource to open and close connection.
  • 5. Persistence.xml file ● Its standard configuration file in JPA it has to be include in the META-INF folder in class directory . ● This file specify that which underline database is suppose to save, update and remove the entity objects . ● This file configure for cache. ● This file configure for object relational mapping .
  • 6. Example 1. <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1"> 2. <persistence-unit name="infinite"> 3. <provider>org.hibernate.ejb.HibernatePersistence</provider> 4. <properties> 5. <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/> 6. <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/> 7. <property name="hibernate.connection.username" value="SRT3"/> 8. <property name="hibernate.connection.password" value="adept"/> 9. <property name="hibernate.connection.url" value="jdbc:oracle:thin:@//v-in-windmill-db-m:1521/optymyze"/> 10. <property name="hibernate.format_sql" value="true"/> 11. <property name="hibernate.hbm2ddl.auto" value="update"/> 12. </properties> 13. </persistence-unit> 14. </persistence>
  • 7. Domain class ● Domain classes are class in an application that implement the entity of business domain. ● An entity is a plain old java object (POJO) and formally it also called as entity bean . ● This class represents a table in the database and instance represents row in that table. ● Requirements ○ Annotation with the javax.persistence.Entity annotation ○ Public or protected non argument constructor ○ The class must not be declare final ○ No instance must not be declare final .
  • 8. Persistence Context ● Persistence context is the set of managed objects of entity manager that exist in particular data store. ● At runtime whenever a session is opened and closed, between those open and close boundaries Hibernate maintains the object in a Persistence Context. Think of it like a first level runtime cache which hibernate controls. ● If an object that has to be retrieved and already exists in the persistence context, the existing managed object is returned without actually accessing the database
  • 9. Instance States ● An instance of the domain class that means domain object can be in one of three states like . 1. Transient state 2. Persistence state 3. Removed state 4. Detached state
  • 10. Operations ● Saving Objects ○ It’s most common operation that we perform in hibernate ○ By using persist method we can save objects. ● Retrieving objects ○ When we working with any sort of ORM or persistence framework we always need to return entity from the database it can be list or a single entity . ○ So we gonna look how we do it with JPA. ● Updating Object ○ Here we see that how to modify persisted instance.
  • 11. Count.. ● Removing Objects ○ Here we remove entity from Database so for that in EntityManager we have remove method by calling .
  • 12. Entity Association When we build an application we are not only writing data to a single table within a data model , entities are related to each other in different ways. Following are the four ways in which the cardinality of the relationship between the objects can be expressed. An association mapping can be unidirectional as well as bidirectional. 1. One-To-One 2. One-To-Many 3. Many-to-One 4. Many-To-Many
  • 13. One-To-One → A one-to-one relationships occurs when one entity is related to exactly one occurrence in another entity. → In this relationship, one object of the one pojo class contains association with one object of the another pojo class. This relationship is supposing a user has only one credential.The navigation is one-way from the credential to the user : it’s possible to know Credential of a User, but not vice-versa.
  • 14. One-To-Many → A one-to-many association is the most common kind of association where an Object can be associated with multiple objects. For example a same Department object can be associated with multiple employee objects. → If the persistent class has list object that contains the entity reference, we need to use one-to-many association to map the list element. Employee and Department table hold One-to-many relationship. Each Department can be associated with multiple Employees and each Employee can have only one Department.
  • 15. Many-To-Many → A logical data relationship in which the value of one data element can exist in combination with many values of another data element, and vice versa. A many-to-many relationship refers to a relationship between tables in a database when a parent row in one table contains several child rows in the second table, and vice versa. → We are using Employee-Meeting relationship as a many to many relationship example. Each Employee can attain more than one meetings and each meetings can have more than one employee
  • 16. Entity Inheritance → Java is an object oriented language and It is possible to implement Inheritance in java and which one of the most visible Object-relational mismatch in Relational model. Object oriented systems can model both “is a” and “has a” relationship but Relational model supports only “has a” relationship between two entities. Hibernate can help you to map such Objects with relational tables. But we need to choose certain mapping strategy based on your needs. There are three types of inheritance mapping in hibernate 1. Table per concrete class 2. Table per class hierarchy(Single Table Strategy) 3. Table per subclass
  • 17. Table Per Class Hierarchy In One Table per Class Hierarchy scheme, we store all the class hierarchy in a single table. A discriminator is a key to uniquely identify the base type of the class hierarchy. Following are the advantages and disadvantages of One Table per Class Hierarchy scheme. Advantage ● This hierarchy offers the best performance since single select may suffice. ● Only one table to deal with. ● Performance wise better than all strategies because no joins need to be performed. .
  • 18. Advantage/Disadvantage Disadvantage ● Changes to members of the hierarchy required column to be altered, added or removed from the table. ● Most of the column of table are nullable so the NOT NULL constraint cannot be applied. ● Tables are not normalized.
  • 19. One Table per Concrete Class In case of Table Per Concrete class, tables are created per class and there are no nullable values in the table. Disadvantage of this approach is that duplicate columns are created in the subclass tables. In this case let's say our Person class is abstract and Employee and Owner are concrete classes. So the table structure that comes out is basically one table for Owner and one table for Employee. The data for Person is duplicated in both the tables.
  • 20. Following are the advantages and disadvantages of One Table per Subclass scheme Advantages This is the easiest method of Inheritance mapping to implement. ● Possible to define NOT NULL constraints on the table. Disadvantages ● Disadvantage of this approach is that duplicate columns are created in the sub tables. ● Changes to a parent class is reflected to large number of tables ● Tables are not normalized.
  • 21. One Table Per Subclass Suppose we have a class Person with subclass Employee and Owner. Following the class diagram and relationship of these classes. In One Table per Subclass scheme, each class persist the data in its own separate table. Thus in this one we have 3 tables; PERSON, EMPLOYEE and OWNER to persist the class data. But a foreign key relationship exists between the sub class tables and superclass table. So the common data is stored in PERSON table and subclass specific fields are stored in EMPLOYEE and OWNER tables.
  • 22. Advantage/Disadvantage Advantage ● Tables are normalized. ● Able to define NOT NULL constraint. ● It works well with shallow hierarchy. Disadvantage ● As the hierarchy grows, it may result in poor performance.
  • 23. Caching Caching is all about application performance optimization and it exists 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. Hibernate second level cache uses a common cache for all the entityManager object of an Entity Manager Factory. It is useful if you have multiple session objects from a session factory. EntityManagerFactory holds the second level cache data. It is global for all the session objects and not enabled by default.