Presentation is loading. Please wait.

Presentation is loading. Please wait.

Rice KRAD Data Layer JPA Design Eric Westfall July 2013.

Similar presentations

Presentation on theme: "Rice KRAD Data Layer JPA Design Eric Westfall July 2013."— Presentation transcript:

1 rice KRAD Data Layer JPA Design Eric Westfall July 2013

2 What is JPA? “Java Persistence API” Framework for managing relational data from Java applications Standardized approach developed through the Java Community Process (JCP) Three main areas: – API for storage/retrieval of entities – JPQL (query language) – Object/Relational Metadata

3 JPA Versions JPA has had three major version releases – 1.0, 2.0, 2.1 We are targeting JPA version 2.1 Fairly recent, finalized April 2013

4 JPA 2.1 Features Converters Bulk Operations Stored Procedure support Database Schema Generation Entity Graphs JPQL/Criteria enhancements Unsynchronized Persistence Contexts

5 Vendor Support for JPA Versions

6 Vendor Neutrality Ideally we would like to stay vendor-neutral and use only JPA features But unfortunately we can’t! Two gaps: – Lack of programmatic access to mapping metadata – Lack of support for custom ID generation strategies Fortunately, this list is fairly small.

7 Vendor Selection Team working on JPA support in KRAD are recommending the use of EclipseLink as the default JPA implementation – Lazy loading semantics are the same as OJB, therefore eases the transition – Is the reference implementation of JPA – Provides us an easy method for programmatic read/write access to metadata – Support for custom identifier generation

8 So why use JPA then? Why not just use EclipseLink-specific annotations and functionality instead of JPA?

9 Design Time! Design Time!

10 Database Plugging JPA into KRAD Data Layer KRAD Data API JPA Persistence Provider JPA Metadata Provider JPA Metadata Provider EclipseLink Client Application Code

11 EntityManager Configuration Spring provides LocalContainerEntityManagerFactoryBean But we’ve created a simpler version to handle setting up KRAD for JPA with EclipseLink

12 JpaPersistenceProvider save – verify the data object is valid and writable – perform "reference linking" (see KRAD Data Layer Design document for information on linking) – execute an EntityManager.merge(...) – return the merged object find – execute an EntityManager.find(...) – return the result findMatching – translate from the Rice QueryByCriteria to a JPA Query and execute it translate the result of the query into Rice QueryResults and return it delete – verify the data object is valid and writable – execute an EntityManager.delete(...)

13 SharedEntityManager Provided by Spring Allows us to inject an EntityManager that is shared across multiple classes Example usage with JpaPersistenceProvider

14 JPA Metadata Provider Provides metadata about Entities managed by the persistence unit Relationships, collections, keys, etc. Pulls what it can from the pure JPA “Metamodel” Gets the rest from EclipseLink-specific APIs


16 Sequences and Generated IDs For Oracle we use native sequences For MySQL we use “_S” tables to simulate sequences Can implement similar behavior using an EclipseLink “SessionCustomizer”

17 Converters Supported natively as of JPA 2.1! Allows for conversion between database and java types For example, storing booleans as “Y” and “N” character data in the database Boolean, KualiDecimal, KualiPercent, KualiInteger, Encrypted values

18 Extension Framework In KNS, allowed for institutions to customize database by adding tables with additional columns and “linking” them to the delivered parent table Required manual copy and modification of OJB mapping files Using programattic metadata modification, can do this programatically now with JPA + EclipseLink


20 Custom DAO’s and Data Access It is still very likely that applications will continue to need custom DAOs for certain cases In these cases, simply create the DAO and inject the shared EntityManager into it and use the JPA apis directly – JPQL – Crteria Query – Etc.

21 Database JPA with krad-data, services, and DAOs KRAD Data API JPA Persistence Provider JPA Metadata Provider JPA Metadata Provider EclipseLink Client Application Code Service API Service Implementation Data Access Object

22 Backend Development 1.Create JPA entities, map with annotations 2.Wire EntityManagerFactory bean in Spring 3.Wire SharedEntityManager bean ins Spring 4.Inject into a JpaPersistenceProvider 5.Inject into a JpaMetadataProvider 6.Register both providers with ModuleConfiguration 7.Use the KRAD DataObjectService!

Download ppt "Rice KRAD Data Layer JPA Design Eric Westfall July 2013."

Similar presentations

Ads by Google