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

PPT
Spring ppt
PPTX
Introduction to Spring Framework
PPTX
Microsoft Purview Overview Deck.pptx is for Microsoft Purview
PDF
Spring Data JPA
PDF
Sécurité des Applications Web avec Json Web Token (JWT)
PPTX
Spring Framework
PPTX
Presentation on Core java
PDF
Hibernate Presentation
Spring ppt
Introduction to Spring Framework
Microsoft Purview Overview Deck.pptx is for Microsoft Purview
Spring Data JPA
Sécurité des Applications Web avec Json Web Token (JWT)
Spring Framework
Presentation on Core java
Hibernate Presentation

What's hot (20)

PPTX
JPA For Beginner's
PDF
JPA and Hibernate
PPT
PDF
Spring Framework - AOP
PPTX
Introduction to spring boot
PDF
Spring Data JPA
PPT
jpa-hibernate-presentation
PPTX
Spring Boot
PPTX
Spring boot
PPTX
Spring boot Introduction
PPTX
Easy data-with-spring-data-jpa
PPTX
Spring boot
PPS
Java Hibernate Programming with Architecture Diagram and Example
PPTX
Spring jdbc
PDF
Enterprise java unit-1_chapter-1
PPT
Spring Core
PPTX
Spring Boot and REST API
PPTX
Introduction to EJB
PPTX
Reactjs
JPA For Beginner's
JPA and Hibernate
Spring Framework - AOP
Introduction to spring boot
Spring Data JPA
jpa-hibernate-presentation
Spring Boot
Spring boot
Spring boot Introduction
Easy data-with-spring-data-jpa
Spring boot
Java Hibernate Programming with Architecture Diagram and Example
Spring jdbc
Enterprise java unit-1_chapter-1
Spring Core
Spring Boot and REST API
Introduction to EJB
Reactjs
Ad

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

PPT
Java persistence api
DOC
Hibernate tutorial for beginners
PPTX
Introduction to JPA (JPA version 2.0)
PPT
02 Hibernate Introduction
PDF
Hibernate Interview Questions and Answers
ODP
What's new in Java EE 6
PPTX
Java se7 features
PDF
Ejb3 Presentation
DOCX
What is hibernate?
DOCX
02 java spring-hibernate-experience-questions
ODP
Javaee6 Overview
PPTX
EJB3 Basics
PPT
J2 Ee Overview
PDF
What is hibernate?
PPTX
Jpa 2.1 Application Development
PDF
Ejb intro
PPTX
Building enterprise web applications with spring 3
PDF
Hibernate 3
Java persistence api
Hibernate tutorial for beginners
Introduction to JPA (JPA version 2.0)
02 Hibernate Introduction
Hibernate Interview Questions and Answers
What's new in Java EE 6
Java se7 features
Ejb3 Presentation
What is hibernate?
02 java spring-hibernate-experience-questions
Javaee6 Overview
EJB3 Basics
J2 Ee Overview
What is hibernate?
Jpa 2.1 Application Development
Ejb intro
Building enterprise web applications with spring 3
Hibernate 3
Ad

More from Guo Albert (20)

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

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Cloud computing and distributed systems.
PDF
Modernizing your data center with Dell and AMD
PDF
Advanced IT Governance
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Sensors and Actuators in IoT Systems using pdf
Per capita expenditure prediction using model stacking based on satellite ima...
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
Cloud computing and distributed systems.
Modernizing your data center with Dell and AMD
Advanced IT Governance
GamePlan Trading System Review: Professional Trader's Honest Take
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Big Data Technologies - Introduction.pptx

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.