SlideShare a Scribd company logo
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.

More Related Content

What's hot

Hibernate
HibernateHibernate
Hibernate
Prashant Kalkar
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
Raji Ghawi
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
Nguyen 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 examples
Er. Gaurav Kumar
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
Ahmed 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 2
Sagar 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
 
Hibernate in Nutshell
Hibernate in NutshellHibernate in Nutshell
Hibernate in Nutshell
Onkar Deshpande
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernatehr1383
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
Ashita Agrawal
 
Hibernate
HibernateHibernate
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
Sakthi Durai
 
JavaEE Spring Seam
JavaEE Spring SeamJavaEE Spring Seam
JavaEE Spring Seam
Carol McDonald
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Java beans
Java beansJava beans

What's hot (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
 

Viewers also liked

Thinking Beyond ORM in JPA
Thinking Beyond ORM in JPAThinking Beyond ORM in JPA
Thinking Beyond ORM in JPA
Patrycja Wegrzynowicz
 
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
Patrycja Wegrzynowicz
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
Mohammad Faizan
 
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
Patrycja Wegrzynowicz
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your development
Strannik_2013
 
Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
Rakesh K. Cherukuri
 
JPA For Beginner's
JPA For Beginner'sJPA For Beginner's
JPA For Beginner's
NarayanaMurthy Ganashree
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
Patrycja Wegrzynowicz
 
JPA - Beyond copy-paste
JPA - Beyond copy-pasteJPA - Beyond copy-paste
JPA - Beyond copy-paste
Jakub Kubrynski
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
Arturs Drozdovs
 
Spring.Boot up your development
Spring.Boot up your developmentSpring.Boot up your development
Spring.Boot up your development
Strannik_2013
 
Spring
SpringSpring
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
Spring Data Jpa
Spring Data JpaSpring Data Jpa
Spring Data Jpa
Ivan Queiroz
 
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
Craig Dickson
 
Junior,middle,senior?
Junior,middle,senior?Junior,middle,senior?
Junior,middle,senior?
Strannik_2013
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
Collaboration Technologies
 
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
Craig 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 MVC
digitalsonic
 

Viewers also liked (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
 

Similar to Hibernate using jpa

Object relationship mapping and hibernate
Object relationship mapping and hibernateObject relationship mapping and hibernate
Object relationship mapping and hibernateJoe Jacob
 
Data Structures & Algorithms
Data Structures & AlgorithmsData Structures & Algorithms
Data Structures & Algorithms
Muhammad Jahanzaib
 
java framwork for HIBERNATE FRAMEWORK.pptx
java framwork for HIBERNATE FRAMEWORK.pptxjava framwork for HIBERNATE FRAMEWORK.pptx
java framwork for HIBERNATE FRAMEWORK.pptx
ramanujsaini2001
 
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
RiturajDas28
 
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.pptMODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
HemaSenthil5
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
Nishant 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 cloud
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
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
Koteswari 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 design
HemaSenthil5
 
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 answers
LakshmiSarvani6
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
Nishant 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 dbms
vikramkagitapu
 
Unit 2 DBMS.pptx
Unit 2 DBMS.pptxUnit 2 DBMS.pptx
Unit 2 DBMS.pptx
ssuserc8e1481
 
DBMS unit 1.pptx
DBMS unit 1.pptxDBMS unit 1.pptx
DBMS unit 1.pptx
ssuserc8e1481
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
SelshaCs
 
DBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdfDBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdf
nofakeNews
 
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
 

Similar to 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
 
java framwork for HIBERNATE FRAMEWORK.pptx
java framwork for HIBERNATE FRAMEWORK.pptxjava framwork for HIBERNATE FRAMEWORK.pptx
java framwork for HIBERNATE FRAMEWORK.pptx
 
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)
 

More from Mohammad Faizan

Jdbc basic features
Jdbc basic featuresJdbc basic features
Jdbc basic features
Mohammad Faizan
 
Tutorial c#
Tutorial c#Tutorial c#
Tutorial c#
Mohammad Faizan
 
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
Mohammad Faizan
 
SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4  SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4
Mohammad Faizan
 
Software maintenance Unit5
Software maintenance  Unit5Software maintenance  Unit5
Software maintenance Unit5
Mohammad Faizan
 
Jvm internal detail
Jvm internal detailJvm internal detail
Jvm internal detail
Mohammad Faizan
 
Unit3 Software engineering UPTU
Unit3 Software engineering UPTUUnit3 Software engineering UPTU
Unit3 Software engineering UPTU
Mohammad Faizan
 
Unit2 Software engineering UPTU
Unit2 Software engineering UPTUUnit2 Software engineering UPTU
Unit2 Software engineering UPTU
Mohammad Faizan
 
Allama Iqbal shiqwa with meaning
Allama Iqbal shiqwa with meaningAllama Iqbal shiqwa with meaning
Allama Iqbal shiqwa with meaning
Mohammad Faizan
 
Coda file system tahir
Coda file system   tahirCoda file system   tahir
Coda file system tahir
Mohammad Faizan
 

More from 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
 

Recently uploaded

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
ShivajiThube2
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 

Recently uploaded (20)

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 

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.