SlideShare ist ein Scribd-Unternehmen logo
1 von 9
JPA version 2.0 Tutorial
                   ejlp12@gmail.com




Dec 2011
Java Persistence API (JPA)

The Java Persistence API provides an object/relational mapping facility
to Java developers for managing relational data in Java applications.
   Provided by the javax.persistence package
   Part of EJB 3.0 specification (JSR 220)
   Enables persisting POJO to relational database

Java Persistence consists of three areas:
• The Java Persistence API
• Object/relational mapping metadata (using annotations or in XML
  deployment descriptor)
• The query language
Entity

An entity is a lightweight persistence domain object.
Typically, represents a table in a relational database
An entity class must follow these requirements:
  annotated with the javax.persistence.Entity annotation.
  have a public or protected, no-argument constructor.
  not be declared final, including methods or persistent instance variables
  If an entity instance be passed by value as a detached object, such as through a
  session bean’s remote business interface, the class must implement the Serializable
  interface.
  may extend both entity and non-entity classes.
  persistent instance variables must be declared private, protected, or package-private,
  and can only be accessed directly by the entity class’s methods (get/set)
Code Example: Entity
Persistence Context & Entity Manager

Persistence context
  a set of managed entity instances that exist in a particular data store.




The EntityManager interface
  defines the methods that are used to interact with the persistence context
  creates and removes persistent entity instances
  finds entities by the entity’s primary key
  allows queries to be run on entities
Entity Manager

Container-Managed Entity Managers
  an EntityManager instance’s persistence context is automatically propagated by the container to all
  application components instance within a single Java Transaction Architecture (JTA) transaction.
  Usually used in Java EE environment


  @PersistenceContext
  EntityManager em;



Application-Managed Entity Managers
  the persistence context is not propagated to application components, and the life cycle
  of EntityManager instances is managed by the application.
  Usually used in Java SE environment


  @PersistenceUnit
  EntityManagerFactory emf;
  EntityManager em = emf.createEntityManager();
Code Example: Insert data (persist object)
XML Configuration files

persistance.xml
  Defines the database and entity manager options for deploying JPA
  applications
  Packaged in the META-INF directory of the project

orm.xml
  Stores metadata to describe object-relational mappings
  Not really required – JPA spec emphasizes using annotation
  Mapping on this file overrides any mapping defined using annotations
persistence.xml in Java SE
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="pu1">
        <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider
>
        <!-- All persistence classes must be listed -->
        <class>entity.Customer</class>
        <class>entity.Order</class>
        <class>entity.Item</class>
        <properties>
            <!-- Provider-specific connection properties -->
            <property name="toplink.jdbc.driver" value="<database driver>"/>
            <property name="toplink.jdbc.url" value="<database url>"/>
            <property name="toplink.jdbc.user" value="<user>"/>
            <property name="toplink.jdbc.password" value="<password>"/>
            <!-- Provider-specific settings -->
            <property name="toplink.logging.level" value="INFO"/>
        </properties>
    </persistence-unit>
</persistence>

Weitere ähnliche Inhalte

Was ist angesagt?

Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Trainingsourabh aggarwal
 
Java persistence api
Java persistence api Java persistence api
Java persistence api Luis Goldster
 
JPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsJPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsosa_ora
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
ORM Concepts and JPA 2.0 Specifications
ORM Concepts and JPA 2.0 SpecificationsORM Concepts and JPA 2.0 Specifications
ORM Concepts and JPA 2.0 SpecificationsAhmed Ramzy
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate TutorialRam132
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate FrameworkRaveendra R
 
Евгений Капинос "Advanced JPA (Java Persistent API)"
Евгений Капинос "Advanced JPA (Java Persistent API)"Евгений Капинос "Advanced JPA (Java Persistent API)"
Евгений Капинос "Advanced JPA (Java Persistent API)"Anna Shymchenko
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Fahad Golra
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentationManav Prasad
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An IntroductionNguyen Cao
 

Was ist angesagt? (20)

Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
Jpa 2.1 Application Development
Jpa 2.1 Application DevelopmentJpa 2.1 Application Development
Jpa 2.1 Application Development
 
Jpa
JpaJpa
Jpa
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Java persistence api
Java persistence api Java persistence api
Java persistence api
 
JPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsJPA 2.1 performance tuning tips
JPA 2.1 performance tuning tips
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Hibernate
HibernateHibernate
Hibernate
 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
 
ORM Concepts and JPA 2.0 Specifications
ORM Concepts and JPA 2.0 SpecificationsORM Concepts and JPA 2.0 Specifications
ORM Concepts and JPA 2.0 Specifications
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
Евгений Капинос "Advanced JPA (Java Persistent API)"
Евгений Капинос "Advanced JPA (Java Persistent API)"Евгений Капинос "Advanced JPA (Java Persistent API)"
Евгений Капинос "Advanced JPA (Java Persistent API)"
 
Deployment
DeploymentDeployment
Deployment
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
 

Andere mochten auch

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
 
Introduction to JavaBeans Activation Framework v1.1
Introduction to JavaBeans Activation Framework v1.1Introduction to JavaBeans Activation Framework v1.1
Introduction to JavaBeans Activation Framework v1.1ejlp12
 
JPA - Java Persistence API
JPA - Java Persistence APIJPA - Java Persistence API
JPA - Java Persistence APIThomas Wöhlke
 
JBoss Data Virtualization (JDV) Sample Physical Deployment Architecture
JBoss Data Virtualization (JDV) Sample Physical Deployment ArchitectureJBoss Data Virtualization (JDV) Sample Physical Deployment Architecture
JBoss Data Virtualization (JDV) Sample Physical Deployment Architectureejlp12
 
WebSphere Application Server Topology Options
WebSphere Application Server Topology OptionsWebSphere Application Server Topology Options
WebSphere Application Server Topology Optionsejlp12
 
GSM/UMTS network architecture tutorial (Indonesia)
GSM/UMTS network architecture tutorial (Indonesia)GSM/UMTS network architecture tutorial (Indonesia)
GSM/UMTS network architecture tutorial (Indonesia)ejlp12
 
Linux container & docker
Linux container & dockerLinux container & docker
Linux container & dockerejlp12
 
WebSphere Application Server Information Resources
WebSphere Application Server Information ResourcesWebSphere Application Server Information Resources
WebSphere Application Server Information Resourcesejlp12
 
BPMN, BPEL, ESB or maybe Java? What should I use to implement my project?
BPMN, BPEL, ESB or maybe Java? What should I use to implement my project?BPMN, BPEL, ESB or maybe Java? What should I use to implement my project?
BPMN, BPEL, ESB or maybe Java? What should I use to implement my project?Guido Schmutz
 
Introduction to jQuery Mobile
Introduction to jQuery MobileIntroduction to jQuery Mobile
Introduction to jQuery Mobileejlp12
 
Arah pengembangan core network architecture (Indonesia)
Arah pengembangan core network architecture (Indonesia)Arah pengembangan core network architecture (Indonesia)
Arah pengembangan core network architecture (Indonesia)ejlp12
 
IBM WebSphere Application Server version to version comparison
IBM WebSphere Application Server version to version comparisonIBM WebSphere Application Server version to version comparison
IBM WebSphere Application Server version to version comparisonejlp12
 
WebSphere Application Server Family (Editions Comparison)
WebSphere Application Server Family (Editions Comparison)WebSphere Application Server Family (Editions Comparison)
WebSphere Application Server Family (Editions Comparison)ejlp12
 
Apps with Apache Cordova and Phonegap
Apps with Apache Cordova and PhonegapApps with Apache Cordova and Phonegap
Apps with Apache Cordova and PhonegapChristian Grobmeier
 
BPEL, BPEL vs ESB (Integration)
BPEL, BPEL vs ESB (Integration)BPEL, BPEL vs ESB (Integration)
BPEL, BPEL vs ESB (Integration)ejlp12
 
Agile & SCRUM
Agile & SCRUMAgile & SCRUM
Agile & SCRUMejlp12
 
Websphere Application Server V8.5
Websphere Application Server V8.5Websphere Application Server V8.5
Websphere Application Server V8.5IBM WebSphereIndia
 

Andere mochten auch (20)

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
 
Introduction à JPA (Java Persistence API )
Introduction à JPA  (Java Persistence API )Introduction à JPA  (Java Persistence API )
Introduction à JPA (Java Persistence API )
 
Introduction to JavaBeans Activation Framework v1.1
Introduction to JavaBeans Activation Framework v1.1Introduction to JavaBeans Activation Framework v1.1
Introduction to JavaBeans Activation Framework v1.1
 
JPA - Java Persistence API
JPA - Java Persistence APIJPA - Java Persistence API
JPA - Java Persistence API
 
JBoss Data Virtualization (JDV) Sample Physical Deployment Architecture
JBoss Data Virtualization (JDV) Sample Physical Deployment ArchitectureJBoss Data Virtualization (JDV) Sample Physical Deployment Architecture
JBoss Data Virtualization (JDV) Sample Physical Deployment Architecture
 
Why do I hate Hibernate?
Why do I hate Hibernate?Why do I hate Hibernate?
Why do I hate Hibernate?
 
WebSphere Application Server Topology Options
WebSphere Application Server Topology OptionsWebSphere Application Server Topology Options
WebSphere Application Server Topology Options
 
GSM/UMTS network architecture tutorial (Indonesia)
GSM/UMTS network architecture tutorial (Indonesia)GSM/UMTS network architecture tutorial (Indonesia)
GSM/UMTS network architecture tutorial (Indonesia)
 
Linux container & docker
Linux container & dockerLinux container & docker
Linux container & docker
 
WebSphere Application Server Information Resources
WebSphere Application Server Information ResourcesWebSphere Application Server Information Resources
WebSphere Application Server Information Resources
 
BPMN, BPEL, ESB or maybe Java? What should I use to implement my project?
BPMN, BPEL, ESB or maybe Java? What should I use to implement my project?BPMN, BPEL, ESB or maybe Java? What should I use to implement my project?
BPMN, BPEL, ESB or maybe Java? What should I use to implement my project?
 
Introduction to jQuery Mobile
Introduction to jQuery MobileIntroduction to jQuery Mobile
Introduction to jQuery Mobile
 
Arah pengembangan core network architecture (Indonesia)
Arah pengembangan core network architecture (Indonesia)Arah pengembangan core network architecture (Indonesia)
Arah pengembangan core network architecture (Indonesia)
 
IBM WebSphere Application Server version to version comparison
IBM WebSphere Application Server version to version comparisonIBM WebSphere Application Server version to version comparison
IBM WebSphere Application Server version to version comparison
 
WebSphere Application Server Family (Editions Comparison)
WebSphere Application Server Family (Editions Comparison)WebSphere Application Server Family (Editions Comparison)
WebSphere Application Server Family (Editions Comparison)
 
Apps with Apache Cordova and Phonegap
Apps with Apache Cordova and PhonegapApps with Apache Cordova and Phonegap
Apps with Apache Cordova and Phonegap
 
BPEL, BPEL vs ESB (Integration)
BPEL, BPEL vs ESB (Integration)BPEL, BPEL vs ESB (Integration)
BPEL, BPEL vs ESB (Integration)
 
Agile & SCRUM
Agile & SCRUMAgile & SCRUM
Agile & SCRUM
 
Websphere Application Server V8.5
Websphere Application Server V8.5Websphere Application Server V8.5
Websphere Application Server V8.5
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 

Ähnlich wie Introduction to JPA (JPA version 2.0)

Ähnlich wie Introduction to JPA (JPA version 2.0) (20)

Configuring jpa in a Spring application
Configuring jpa in a  Spring applicationConfiguring jpa in a  Spring application
Configuring jpa in a Spring application
 
Javaee6 Overview
Javaee6 OverviewJavaee6 Overview
Javaee6 Overview
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
OSGi Persistence With EclipseLink
OSGi Persistence With EclipseLinkOSGi Persistence With EclipseLink
OSGi Persistence With EclipseLink
 
What's new in Java EE 6
What's new in Java EE 6What's new in Java EE 6
What's new in Java EE 6
 
Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
Mobicents JSLEE progress and roadmap - Mobicents Summit 2011Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
 
02 Hibernate Introduction
02 Hibernate Introduction02 Hibernate Introduction
02 Hibernate Introduction
 
Hibernate
HibernateHibernate
Hibernate
 
Java EE and Glassfish
Java EE and GlassfishJava EE and Glassfish
Java EE and Glassfish
 
Sel study notes
Sel study notesSel study notes
Sel study notes
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
 
Hibernate
HibernateHibernate
Hibernate
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi Style
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi Style
 
Introduction to Datastore
Introduction to DatastoreIntroduction to Datastore
Introduction to Datastore
 
Getting Started with Java EE 7
Getting Started with Java EE 7Getting Started with Java EE 7
Getting Started with Java EE 7
 
JDBC
JDBCJDBC
JDBC
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
 
J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 

Mehr von ejlp12

Introduction to Docker storage, volume and image
Introduction to Docker storage, volume and imageIntroduction to Docker storage, volume and image
Introduction to Docker storage, volume and imageejlp12
 
Java troubleshooting thread dump
Java troubleshooting thread dumpJava troubleshooting thread dump
Java troubleshooting thread dumpejlp12
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuseejlp12
 
BPMN Introduction
BPMN IntroductionBPMN Introduction
BPMN Introductionejlp12
 
IBM WebSphere Application Server (Clustering) Concept
IBM WebSphere Application Server (Clustering) ConceptIBM WebSphere Application Server (Clustering) Concept
IBM WebSphere Application Server (Clustering) Conceptejlp12
 
IBM WebSphere MQ Introduction
IBM WebSphere MQ Introduction IBM WebSphere MQ Introduction
IBM WebSphere MQ Introduction ejlp12
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introductionejlp12
 
Introduction to Apache Cordova (Phonegap)
Introduction to Apache Cordova (Phonegap)Introduction to Apache Cordova (Phonegap)
Introduction to Apache Cordova (Phonegap)ejlp12
 
PMP Training - 11 project risk management
PMP Training - 11 project risk managementPMP Training - 11 project risk management
PMP Training - 11 project risk managementejlp12
 
PMP Training - 10 project communication management
PMP Training - 10 project communication managementPMP Training - 10 project communication management
PMP Training - 10 project communication managementejlp12
 
PMP Training - 09 project human resource management
PMP Training - 09 project human resource managementPMP Training - 09 project human resource management
PMP Training - 09 project human resource managementejlp12
 
PMP Training - 08 project quality management
PMP Training - 08 project quality managementPMP Training - 08 project quality management
PMP Training - 08 project quality managementejlp12
 
PMP Training - 12 project procurement management
PMP Training - 12 project procurement managementPMP Training - 12 project procurement management
PMP Training - 12 project procurement managementejlp12
 
PMP Training - 07 project cost management
PMP Training - 07 project cost managementPMP Training - 07 project cost management
PMP Training - 07 project cost managementejlp12
 
PMP Training - 06 project time management2
PMP Training - 06 project time management2PMP Training - 06 project time management2
PMP Training - 06 project time management2ejlp12
 
PMP Training - 05 project scope management
PMP Training - 05 project scope managementPMP Training - 05 project scope management
PMP Training - 05 project scope managementejlp12
 
PMP Training - 04 project integration management
PMP Training - 04 project integration managementPMP Training - 04 project integration management
PMP Training - 04 project integration managementejlp12
 
PMP Training - 01 introduction to framework
PMP Training - 01 introduction to frameworkPMP Training - 01 introduction to framework
PMP Training - 01 introduction to frameworkejlp12
 

Mehr von ejlp12 (18)

Introduction to Docker storage, volume and image
Introduction to Docker storage, volume and imageIntroduction to Docker storage, volume and image
Introduction to Docker storage, volume and image
 
Java troubleshooting thread dump
Java troubleshooting thread dumpJava troubleshooting thread dump
Java troubleshooting thread dump
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuse
 
BPMN Introduction
BPMN IntroductionBPMN Introduction
BPMN Introduction
 
IBM WebSphere Application Server (Clustering) Concept
IBM WebSphere Application Server (Clustering) ConceptIBM WebSphere Application Server (Clustering) Concept
IBM WebSphere Application Server (Clustering) Concept
 
IBM WebSphere MQ Introduction
IBM WebSphere MQ Introduction IBM WebSphere MQ Introduction
IBM WebSphere MQ Introduction
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
Introduction to Apache Cordova (Phonegap)
Introduction to Apache Cordova (Phonegap)Introduction to Apache Cordova (Phonegap)
Introduction to Apache Cordova (Phonegap)
 
PMP Training - 11 project risk management
PMP Training - 11 project risk managementPMP Training - 11 project risk management
PMP Training - 11 project risk management
 
PMP Training - 10 project communication management
PMP Training - 10 project communication managementPMP Training - 10 project communication management
PMP Training - 10 project communication management
 
PMP Training - 09 project human resource management
PMP Training - 09 project human resource managementPMP Training - 09 project human resource management
PMP Training - 09 project human resource management
 
PMP Training - 08 project quality management
PMP Training - 08 project quality managementPMP Training - 08 project quality management
PMP Training - 08 project quality management
 
PMP Training - 12 project procurement management
PMP Training - 12 project procurement managementPMP Training - 12 project procurement management
PMP Training - 12 project procurement management
 
PMP Training - 07 project cost management
PMP Training - 07 project cost managementPMP Training - 07 project cost management
PMP Training - 07 project cost management
 
PMP Training - 06 project time management2
PMP Training - 06 project time management2PMP Training - 06 project time management2
PMP Training - 06 project time management2
 
PMP Training - 05 project scope management
PMP Training - 05 project scope managementPMP Training - 05 project scope management
PMP Training - 05 project scope management
 
PMP Training - 04 project integration management
PMP Training - 04 project integration managementPMP Training - 04 project integration management
PMP Training - 04 project integration management
 
PMP Training - 01 introduction to framework
PMP Training - 01 introduction to frameworkPMP Training - 01 introduction to framework
PMP Training - 01 introduction to framework
 

Kürzlich hochgeladen

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Kürzlich hochgeladen (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Introduction to JPA (JPA version 2.0)

  • 1. JPA version 2.0 Tutorial ejlp12@gmail.com Dec 2011
  • 2. Java Persistence API (JPA) The Java Persistence API provides an object/relational mapping facility to Java developers for managing relational data in Java applications. Provided by the javax.persistence package Part of EJB 3.0 specification (JSR 220) Enables persisting POJO to relational database Java Persistence consists of three areas: • The Java Persistence API • Object/relational mapping metadata (using annotations or in XML deployment descriptor) • The query language
  • 3. Entity An entity is a lightweight persistence domain object. Typically, represents a table in a relational database An entity class must follow these requirements: annotated with the javax.persistence.Entity annotation. have a public or protected, no-argument constructor. not be declared final, including methods or persistent instance variables If an entity instance be passed by value as a detached object, such as through a session bean’s remote business interface, the class must implement the Serializable interface. may extend both entity and non-entity classes. persistent instance variables must be declared private, protected, or package-private, and can only be accessed directly by the entity class’s methods (get/set)
  • 5. Persistence Context & Entity Manager Persistence context a set of managed entity instances that exist in a particular data store. The EntityManager interface defines the methods that are used to interact with the persistence context creates and removes persistent entity instances finds entities by the entity’s primary key allows queries to be run on entities
  • 6. Entity Manager Container-Managed Entity Managers an EntityManager instance’s persistence context is automatically propagated by the container to all application components instance within a single Java Transaction Architecture (JTA) transaction. Usually used in Java EE environment @PersistenceContext EntityManager em; Application-Managed Entity Managers the persistence context is not propagated to application components, and the life cycle of EntityManager instances is managed by the application. Usually used in Java SE environment @PersistenceUnit EntityManagerFactory emf; EntityManager em = emf.createEntityManager();
  • 7. Code Example: Insert data (persist object)
  • 8. XML Configuration files persistance.xml Defines the database and entity manager options for deploying JPA applications Packaged in the META-INF directory of the project orm.xml Stores metadata to describe object-relational mappings Not really required – JPA spec emphasizes using annotation Mapping on this file overrides any mapping defined using annotations
  • 9. persistence.xml in Java SE <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> <persistence-unit name="pu1"> <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider > <!-- All persistence classes must be listed --> <class>entity.Customer</class> <class>entity.Order</class> <class>entity.Item</class> <properties> <!-- Provider-specific connection properties --> <property name="toplink.jdbc.driver" value="<database driver>"/> <property name="toplink.jdbc.url" value="<database url>"/> <property name="toplink.jdbc.user" value="<user>"/> <property name="toplink.jdbc.password" value="<password>"/> <!-- Provider-specific settings --> <property name="toplink.logging.level" value="INFO"/> </properties> </persistence-unit> </persistence>