SlideShare a Scribd company logo
Albert Guo [email_address]
What is Java Persistence API  Primary Features Five Steps to Implement JPA Download Hibernate Components Prepare Database, and Download JDBC Driver Implemented POJO entities and add annotations Persistence.xml Implemented client side code via EntityManager
The Java Persistence API is the standard object/relational mapping and persistence management interface of the  Java EE 5.0  platform. As part of the  EJB 3.0  specification effort, it is supported by all major vendors of the Java industry.
Inheritance, polymorphism, etc. Using annotations and/or XML
Java Application Java Persistence API Hibernate TopLink Kodo (OpenJPA) Everyone can use their own favorite persistence technology
Hibernate Core Hibernate Annotation (JPA) Hibernate EntityManager Hibernate Annotation (Hibernate) Hibernate XML Mapping File Java Persistence API Hibernate API
1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/   MySQL JDBC Driver http://tinyurl.com/ymt6rb
1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/   MySQL JDBC Driver http://tinyurl.com/ymt6rb
To label artifacts  (classes, methods etc.) for  persistence or persistence  related operations A “gateway” to the  persistence classes Allow access to persistent  objects, transaction context,  query language etc.
Hibernate Annotations includes Standardized Java Persistence and EJB 3.0 (JSR 220) object/relational mapping annotations Hibernate-specific extension annotations for performance optimization and special mappings Hibernate EntityManager includes The standard Java Persistence management API The standard Java Persistence Query Language The standard Java Persistence object lifecycle rules The standard Java Persistence configuration and packaging
1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/   MySQL JDBC Driver http://tinyurl.com/ymt6rb
 
 
Attached to a class Signify that a class is persistent Example: An entity must follow the Java Bean convention for its attributes to be  persistent Having getters and setters
Each entity must have an identity An identity of an entity could simply be a class variable annotated with @Id Example
Id can be auto generated @Id(generate=GeneratorType.AUTO) There are other strategies such as  GeneratorType.SEQUENCE GeneratorType.IDENTITY AUTO is best for portability between database vendors
@Column, is put on getter of a class variable  Has several functionalities Updatable (boolean) Nullable (updatable) Length (int) Example:
There are 4 types of links @OneToOne @OneToMany @ManyToOne @ManyToMany In most cases, putting the annotation on a getter of a class variable would be enough In some cases, we need to identify a few parameters to the annotations
Two cases Two entities share the same primary key value
Entity objects have two distinct modes Attached The object is in the database Detached The object is in memory acting as a DTO Modification on detached object would not be persisted automatically Developers need to persist detached objects using a primitive
Entity manager:  Gateway to persistent classes Enable queries Outside of session beans, provides transaction facility
1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/   MySQL JDBC Driver http://tinyurl.com/ymt6rb
Entity classes JDBC Driver JDBC URL User name password EntityManagerFactory Name
1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/   MySQL JDBC Driver http://tinyurl.com/ymt6rb
Create Create Operates Persistence.xml
 
 
 
 

More Related Content

What's hot (20)

PPT
jpa-hibernate-presentation
John Slick
 
PDF
JPA and Hibernate
elliando dias
 
PPTX
JPA For Beginner's
NarayanaMurthy Ganashree
 
PDF
Spring Data JPA
Knoldus Inc.
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
PPTX
Spring boot
Pradeep Shanmugam
 
PPTX
Spring boot Introduction
Jeevesh Pandey
 
PDF
Spring Data JPA
Cheng Ta Yeh
 
PDF
Hibernate Presentation
guest11106b
 
PDF
Spring Boot
Jaran Flaath
 
PPTX
Introduction to Spring Boot
Purbarun Chakrabarti
 
PPTX
Introduction to spring boot
Santosh Kumar Kar
 
PPTX
Spring boot
sdeeg
 
PDF
Spring boot introduction
Rasheed Waraich
 
PPTX
Spring Security 5
Jesus Perez Franco
 
PDF
REST APIs with Spring
Joshua Long
 
PPTX
An Introduction To REST API
Aniruddh Bhilvare
 
PPTX
Java 8 lambda
Manav Prasad
 
PPTX
Spring boot
Gyanendra Yadav
 
PDF
Introduction to JPA and Hibernate including examples
ecosio GmbH
 
jpa-hibernate-presentation
John Slick
 
JPA and Hibernate
elliando dias
 
JPA For Beginner's
NarayanaMurthy Ganashree
 
Spring Data JPA
Knoldus Inc.
 
Spring Framework - Core
Dzmitry Naskou
 
Spring boot
Pradeep Shanmugam
 
Spring boot Introduction
Jeevesh Pandey
 
Spring Data JPA
Cheng Ta Yeh
 
Hibernate Presentation
guest11106b
 
Spring Boot
Jaran Flaath
 
Introduction to Spring Boot
Purbarun Chakrabarti
 
Introduction to spring boot
Santosh Kumar Kar
 
Spring boot
sdeeg
 
Spring boot introduction
Rasheed Waraich
 
Spring Security 5
Jesus Perez Franco
 
REST APIs with Spring
Joshua Long
 
An Introduction To REST API
Aniruddh Bhilvare
 
Java 8 lambda
Manav Prasad
 
Spring boot
Gyanendra Yadav
 
Introduction to JPA and Hibernate including examples
ecosio GmbH
 

Similar to Java Persistence API (JPA) Step By Step (20)

PPT
Java persistence api
Luis Goldster
 
DOC
Hibernate tutorial for beginners
Rahul Jain
 
PPTX
Introduction to JPA (JPA version 2.0)
ejlp12
 
PPT
02 Hibernate Introduction
Ranjan Kumar
 
PDF
Hibernate Interview Questions and Answers
AnuragMourya8
 
ODP
What's new in Java EE 6
Antonio Goncalves
 
PPTX
Java se7 features
Kumaraswamy M
 
PDF
Ejb3 Presentation
Saurabh Raisinghani
 
DOCX
What is hibernate?
kanchanmahajan23
 
DOCX
02 java spring-hibernate-experience-questions
Dhiraj Champawat
 
ODP
Javaee6 Overview
Carol McDonald
 
PPTX
EJB3 Basics
Emprovise
 
PPT
J2 Ee Overview
Atul Shridhar
 
PDF
What is hibernate?
kanchanmahajan23
 
PPTX
Jpa 2.1 Application Development
ThirupathiReddy Vajjala
 
PDF
Ejb intro
MANOJ KUMAR
 
PPTX
Building enterprise web applications with spring 3
Abdelmonaim Remani
 
PDF
Hibernate 3
Rajiv Gupta
 
Java persistence api
Luis Goldster
 
Hibernate tutorial for beginners
Rahul Jain
 
Introduction to JPA (JPA version 2.0)
ejlp12
 
02 Hibernate Introduction
Ranjan Kumar
 
Hibernate Interview Questions and Answers
AnuragMourya8
 
What's new in Java EE 6
Antonio Goncalves
 
Java se7 features
Kumaraswamy M
 
Ejb3 Presentation
Saurabh Raisinghani
 
What is hibernate?
kanchanmahajan23
 
02 java spring-hibernate-experience-questions
Dhiraj Champawat
 
Javaee6 Overview
Carol McDonald
 
EJB3 Basics
Emprovise
 
J2 Ee Overview
Atul Shridhar
 
What is hibernate?
kanchanmahajan23
 
Jpa 2.1 Application Development
ThirupathiReddy Vajjala
 
Ejb intro
MANOJ KUMAR
 
Building enterprise web applications with spring 3
Abdelmonaim Remani
 
Hibernate 3
Rajiv Gupta
 
Ad

More from Guo Albert (20)

PPTX
AWS IAM (Identity and Access Management) Policy Simulator
Guo Albert
 
PPTX
TOEIC 準備心得
Guo Albert
 
PDF
DBM專案環境建置
Guo Albert
 
PDF
JPA Optimistic Locking With @Version
Guo Albert
 
PDF
OCEJPA Study Notes
Guo Albert
 
PPTX
OCEJPA(1Z0-898) Preparation Tips
Guo Albert
 
PPTX
JPA lifecycle events practice
Guo Albert
 
PPTX
XDate - a modern java-script date library
Guo Albert
 
PDF
How to avoid check style errors
Guo Albert
 
PDF
NIG系統報表開發指南
Guo Albert
 
PDF
Ease Your Effort of Putting Data into History Table
Guo Albert
 
PDF
NIG 系統開發指引
Guo Albert
 
PDF
NIG系統開發文件閱讀步驟
Guo Albert
 
PDF
Form Bean Creation Process for NIG System
Guo Albert
 
PDF
A Short Intorduction to JasperReports
Guo Albert
 
PPTX
Apply Template Method Pattern in Report Implementation
Guo Albert
 
PPTX
Utilize Commons BeansUtils to do copy object
Guo Albert
 
PPTX
Apply my eclipse to do entity class generation
Guo Albert
 
PPTX
Nig project setup quickly tutorial
Guo Albert
 
PPTX
Spring JDBCTemplate
Guo Albert
 
AWS IAM (Identity and Access Management) Policy Simulator
Guo Albert
 
TOEIC 準備心得
Guo Albert
 
DBM專案環境建置
Guo Albert
 
JPA Optimistic Locking With @Version
Guo Albert
 
OCEJPA Study Notes
Guo Albert
 
OCEJPA(1Z0-898) Preparation Tips
Guo Albert
 
JPA lifecycle events practice
Guo Albert
 
XDate - a modern java-script date library
Guo Albert
 
How to avoid check style errors
Guo Albert
 
NIG系統報表開發指南
Guo Albert
 
Ease Your Effort of Putting Data into History Table
Guo Albert
 
NIG 系統開發指引
Guo Albert
 
NIG系統開發文件閱讀步驟
Guo Albert
 
Form Bean Creation Process for NIG System
Guo Albert
 
A Short Intorduction to JasperReports
Guo Albert
 
Apply Template Method Pattern in Report Implementation
Guo Albert
 
Utilize Commons BeansUtils to do copy object
Guo Albert
 
Apply my eclipse to do entity class generation
Guo Albert
 
Nig project setup quickly tutorial
Guo Albert
 
Spring JDBCTemplate
Guo Albert
 
Ad

Recently uploaded (20)

PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Digital Circuits, important subject in CS
contactparinay1
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 

Java Persistence API (JPA) Step By Step

  • 2. What is Java Persistence API Primary Features Five Steps to Implement JPA Download Hibernate Components Prepare Database, and Download JDBC Driver Implemented POJO entities and add annotations Persistence.xml Implemented client side code via EntityManager
  • 3. The Java Persistence API is the standard object/relational mapping and persistence management interface of the Java EE 5.0 platform. As part of the EJB 3.0 specification effort, it is supported by all major vendors of the Java industry.
  • 4. Inheritance, polymorphism, etc. Using annotations and/or XML
  • 5. Java Application Java Persistence API Hibernate TopLink Kodo (OpenJPA) Everyone can use their own favorite persistence technology
  • 6. Hibernate Core Hibernate Annotation (JPA) Hibernate EntityManager Hibernate Annotation (Hibernate) Hibernate XML Mapping File Java Persistence API Hibernate API
  • 7. 1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/ MySQL JDBC Driver http://tinyurl.com/ymt6rb
  • 8. 1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/ MySQL JDBC Driver http://tinyurl.com/ymt6rb
  • 9. To label artifacts (classes, methods etc.) for persistence or persistence related operations A “gateway” to the persistence classes Allow access to persistent objects, transaction context, query language etc.
  • 10. Hibernate Annotations includes Standardized Java Persistence and EJB 3.0 (JSR 220) object/relational mapping annotations Hibernate-specific extension annotations for performance optimization and special mappings Hibernate EntityManager includes The standard Java Persistence management API The standard Java Persistence Query Language The standard Java Persistence object lifecycle rules The standard Java Persistence configuration and packaging
  • 11. 1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/ MySQL JDBC Driver http://tinyurl.com/ymt6rb
  • 12.  
  • 13.  
  • 14. Attached to a class Signify that a class is persistent Example: An entity must follow the Java Bean convention for its attributes to be persistent Having getters and setters
  • 15. Each entity must have an identity An identity of an entity could simply be a class variable annotated with @Id Example
  • 16. Id can be auto generated @Id(generate=GeneratorType.AUTO) There are other strategies such as GeneratorType.SEQUENCE GeneratorType.IDENTITY AUTO is best for portability between database vendors
  • 17. @Column, is put on getter of a class variable Has several functionalities Updatable (boolean) Nullable (updatable) Length (int) Example:
  • 18. There are 4 types of links @OneToOne @OneToMany @ManyToOne @ManyToMany In most cases, putting the annotation on a getter of a class variable would be enough In some cases, we need to identify a few parameters to the annotations
  • 19. Two cases Two entities share the same primary key value
  • 20. Entity objects have two distinct modes Attached The object is in the database Detached The object is in memory acting as a DTO Modification on detached object would not be persisted automatically Developers need to persist detached objects using a primitive
  • 21. Entity manager: Gateway to persistent classes Enable queries Outside of session beans, provides transaction facility
  • 22. 1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/ MySQL JDBC Driver http://tinyurl.com/ymt6rb
  • 23. Entity classes JDBC Driver JDBC URL User name password EntityManagerFactory Name
  • 24. 1. Hibernate Core 2. Hibernate EntityManager 3. Hibernate Annotations http://www.hibernate.org/ MySQL JDBC Driver http://tinyurl.com/ymt6rb
  • 25. Create Create Operates Persistence.xml
  • 26.  
  • 27.  
  • 28.  
  • 29.