Your SlideShare is downloading. ×
0
<Insert Picture Here>TopLink Grid: Scaling JPA applications withCoherenceAndrei Cristian NiculaeTechnology Presales Consul...
The following is intended to outline our generalproduct direction. It is intended for informationpurposes only, and may no...
Java Persistence: The Problem Space    Customer                         <customer id=“…”>                                 ...
Oracle TopLink 11gR1• Comprehensive Persistence Solution  • Java Persistence (JPA 2.0 Reference Implementation), Java Arch...
Java Persistence API (JPA)—in a Nutshell• A Java standard that defines:  • how Java objects are stored in relational datab...
JPA—Background•   JPA 1.0 part of EJB 3.0 JSR 220•   JPA 2.0 standalone JSR 317•   JPA 2.1 (JSR 338) included in Java EE 7...
JPA—POJO Entities• Abstract or concrete top level Java class    • Non-final fields/properties, no-arg constructor• No requ...
Mapping• The activity of „Mapping‟ is the process of connecting  objects/attributes to tables/columns        Customer     ...
JPA Object-Relational Mappings• Core JPA Mappings  • Id  • Basic  • Relationships     • OneToOne     • ManyToOne     • One...
Annotations on Fields@Entitypublic class Customer {     @Id     private String name;     @OneToOne     private Account acc...
Annotations on Properties@Entitypublic class Customer {     private String name;     private Account account;     @Id     ...
Mappings in XML <entity-mappings   xmlns="http://java.sun.com/xml/ns/persistence/orm" …   <entity class=“Customer">     <a...
EclipseLink JPA Developer ToolSupport         Eclipse IDE            EclipseLink support included by Dali in            ...
Example JPA Client Code…
Mechanics of a JPA Application     Step 1               Step 2              Step 3   Application Logic   Application Logic...
JPA with Shared Cache             TX n                     TX n+1         Application Logic         Application Logic     ...
Application       Application       Application JPA       Application       Application       Application       Applicatio...
EclipseLink in a Cluster   Application Logic                      Application Logic     EntityManager                     ...
Traditional Approaches to Scaling JPA• Historically there have been two strategies for scaling  EclipseLink JPA applicatio...
Strategy 1: Disable Shared Cache   Application Logic      Application Logic     EntityManager          EntityManager Persi...
Disable Shared Cache• Ensures all nodes have coherent view of data.  • Database is always right  • Each transaction querie...
Strategy 2: Cache Coordination   Application Logic                     Application Logic     EntityManager                ...
Cache Coordination• Minimize stale entity caching across loosely coupled nodes.   • Database is always right      • Optimi...
Introducing TopLink Grid• TopLink Grid allows Java developers to transparently  leverage the power of the Coherence data g...
Oracle TopLink 11gR1• Oracle‟s Enterprise Java Persistence Framework  • Includes open source EclipseLink with Commercial  ...
TopLink Grid with Coherence Cache   Application Logic                  Application Logic     EntityManager                ...
Oracle Coherence Data GridDistributed in Memory Data Management                                               • Provides a...
Coherence Topology Example     Distributed Topology     • Data spread and       backed up across       Members     • Trans...
Coherence Update Example     Distributed Topology     • Synchronous Update     • Avoids potential Data       Loss & Corrup...
Coherence Recovery Example     Distributed Topology     • No in-flight       operations lost     • Some latencies (due    ...
JPA with Coherence  Cluster Node 1                      Cluster Node N   Application Logic                   Application L...
TopLink Grid—Configurations• Grid Cache—Coherence as Shared (L2) Cache  • Configurable per Entity type  • Entities read by...
Grid Cache (Cache Aside)•   Reading:    •   Primary Key queries check           JPA Application        Coherence first.   ...
Grid Cache—Leveraging Cache• Cache is used when processing database results• EclipseLink extracts primary keys from result...
Grid Read•   All writes performed directly    JPA Application    on database.•   Primary key queries result in    get() on...
Coherence Cache            Application Logic              EntityManager          Persistence          Context         Enti...
Coherence Cache                   Application Logic                    EntityManager                 Persistence          ...
How is TopLink Grid different from Hibernate with Coherence?• Hibernate does not cache objects, it caches data rows  in Co...
Summary• EclipseLink supports a unique range of strategies for  scaling JPA applications• TopLink Grid provides:  • An eas...
Q U E S T I O N S A N S W E R S
Upcoming SlideShare
Loading in...5
×

Introduction to JPA and TopLink Grid

2,597

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,597
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
82
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Introduction to JPA and TopLink Grid"

  1. 1. <Insert Picture Here>TopLink Grid: Scaling JPA applications withCoherenceAndrei Cristian NiculaeTechnology Presales Consultant
  2. 2. The following is intended to outline our generalproduct direction. It is intended for informationpurposes only, and may not be incorporated into anycontract. It is not a commitment to deliver anymaterial, code, or functionality, and should not berelied upon in making purchasing decisions.The development, release, and timing of anyfeatures or functionality described for Oracle‟sproducts remains at the sole discretion of Oracle. 2
  3. 3. Java Persistence: The Problem Space Customer <customer id=“…”> <name>…</name> id: int JAXB/SDO <contact-info> name: String … creditRating: int </contact-info> </customer> Java XML DBWS JPA CUST ID NAME C_RATING JPA: Java Persistence API JAXB: Java Architecture for XML Binding Relational SDO: Service Data Objects DBWS: Database WebServices
  4. 4. Oracle TopLink 11gR1• Comprehensive Persistence Solution • Java Persistence (JPA 2.0 Reference Implementation), Java Architecture for XML Binding (JAXB 2.x), Database Web Service (DBWS)• Strong Developer Support • Developed in open source EclipseLink project at Eclipse.org • Tool support in OEPE (Eclipse EE), NetBeans, JDeveloper• Widely Used • The enterprise persistence provider for WebLogic and GlassFish • EclipseLink distributed with Spring, JOnAS, NetWeaver (soon)• Performance • Key contributor to Oracles SpecJ World Record • Superior results across the board against key competitors in internal benchmarks• Best Java Persistence for the Oracle DB and other DBs
  5. 5. Java Persistence API (JPA)—in a Nutshell• A Java standard that defines: • how Java objects are stored in relational databases (specified using a standard set of mappings) • a programmer API for reading, writing, and querying persistent Java objects (“Entities”) • a full featured query language • a container contract that supports plugging any JPA runtime in to any compliant container.
  6. 6. JPA—Background• JPA 1.0 part of EJB 3.0 JSR 220• JPA 2.0 standalone JSR 317• JPA 2.1 (JSR 338) included in Java EE 7• Suitable for use in different modes • Standalone in Java SE environment • Hosted within a Java EE Container• Standardization of current persistence practices• Merging of expertise from persistence vendors and communities including: TopLink, Hibernate, JDO, EJB vendors and individuals
  7. 7. JPA—POJO Entities• Abstract or concrete top level Java class • Non-final fields/properties, no-arg constructor• No required interfaces • No required business or callback interfaces (but you may use them if you want to)• Direct field or property-based access • Getter/setter can contain logic (e.g. for validation)• May be Serializable, but not required • Only needed if passed by value (in a remote call)
  8. 8. Mapping• The activity of „Mapping‟ is the process of connecting objects/attributes to tables/columns Customer CUST id: int ID NAME C_RATING name: String creditRating: int
  9. 9. JPA Object-Relational Mappings• Core JPA Mappings • Id • Basic • Relationships • OneToOne • ManyToOne • OneToMany • ManyToMany • And more…• Annotations and/or XML
  10. 10. Annotations on Fields@Entitypublic class Customer { @Id private String name; @OneToOne private Account account; public String getName() { return name; } public void setName(String name) { this.name = name; } public Account getAccount() { return account; } public void setAccount(Account account) { this.account = account; }}
  11. 11. Annotations on Properties@Entitypublic class Customer { private String name; private Account account; @Id public String getName() { return name; } public void setName(String name) { this.name = name; } @OneToOne public Account getAccount() { return account; } public void setAccount(Account account) { this.account = account; }}
  12. 12. Mappings in XML <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" … <entity class=“Customer"> <attributes> <id name=“name“/> <one-to-one name=“account“/> </attributes> </entity> … </entity-mappings>
  13. 13. EclipseLink JPA Developer ToolSupport  Eclipse IDE  EclipseLink support included by Dali in Eclipse WTP Dali supports download and install of EclipseLink into IDE  Oracle Enterprise Pack for Eclipse (OEPE)  JDeveloper 11g  JPA, JAXB, Native ORM, and Native OXM  NetBeans
  14. 14. Example JPA Client Code…
  15. 15. Mechanics of a JPA Application Step 1 Step 2 Step 3 Application Logic Application Logic Application Logic Create/ Modify Entities JPA JPA JPA Read Insert/ Entities Update Entities
  16. 16. JPA with Shared Cache TX n TX n+1 Application Logic Application Logic Cache hits JPA avoid object build cost Read TX Commit Entities
  17. 17. Application Application Application JPA Application Application Application Application Application JPA Application Application Scaling Java Persistence... Application Application Application JPA Application Application
  18. 18. EclipseLink in a Cluster Application Logic Application Logic EntityManager EntityManager Persistence Persistence Context ContextEntityManagerFactory EntityManagerFactory Need to keep Shared Shared Caches Shared Cache Coherent Cache
  19. 19. Traditional Approaches to Scaling JPA• Historically there have been two strategies for scaling EclipseLink JPA applications into a cluster: • Disable Shared Caching • No shared cache • Always Refresh • Cache Coordination • Communicate changes via messaging
  20. 20. Strategy 1: Disable Shared Cache Application Logic Application Logic EntityManager EntityManager Persistence Persistence Context ContextEntityManagerFactory EntityManagerFactory
  21. 21. Disable Shared Cache• Ensures all nodes have coherent view of data. • Database is always right • Each transaction queries all required data from database and constructs Entities• No inter-node messaging• Memory footprint of application increases as each transaction has a copy of each required Entity• Every transaction pays object construction cost for queried Entities.• Database becomes bottleneck
  22. 22. Strategy 2: Cache Coordination Application Logic Application Logic EntityManager EntityManager Persistence Persistence Context ContextEntityManagerFactory EntityManagerFactory Shared Cache Shared Cache Coordination Cache
  23. 23. Cache Coordination• Minimize stale entity caching across loosely coupled nodes. • Database is always right • Optimistic locking prevents corruption • Fresh Entities retrieved from shared cache • Stale Entities refreshed from database on access• Creation and/or modification of Entity results in message to all other nodes• Shared cache size limited by heap of each node• Cost of coordinating depends on messaging technology and application • cost of communication and processing may eventually exceed value of caching
  24. 24. Introducing TopLink Grid• TopLink Grid allows Java developers to transparently leverage the power of the Coherence data grid• TopLink Grid combines: • the simplicity of application development using the Java standard Java Persistence API (JPA) with • the scalability and distributed processing power of Oracle‟s Coherence Data Grid.• Supports JPA on the Grid Architecture • EclipseLink JPA applications using Coherence as a shared (L2) cache replacement along with configuration for more advanced usage
  25. 25. Oracle TopLink 11gR1• Oracle‟s Enterprise Java Persistence Framework • Includes open source EclipseLink with Commercial Support • Certified on WebLogic and redistributed by Oracle as part of TopLink product and in WebLogic Server and Oracle GlassFish • TopLink Grid: JPA integration with Coherence
  26. 26. TopLink Grid with Coherence Cache Application Logic Application Logic EntityManager EntityManager Persistence Persistence Context ContextEntityManagerFactory EntityManagerFactory Coherence
  27. 27. Oracle Coherence Data GridDistributed in Memory Data Management • Provides a reliable data WebEnterpriseApplications Real Time Clients Services tier with a single, consistent view of data Data Services • Enables dynamic data capacity including fault Oracle Coherence tolerance and load Data Grid balancing • Ensures that data capacity scales withDatabases Mainframes Web Services processing capacity
  28. 28. Coherence Topology Example Distributed Topology • Data spread and backed up across Members • Transparent to developer • Members have access to all Data • All Data locations are known – no lookup & no registry!28
  29. 29. Coherence Update Example Distributed Topology • Synchronous Update • Avoids potential Data Loss & Corruption • Predictable Performance • Backup Partitions are partitioned away from Primaries for resilience • No engineering requirement to setup Primaries or Backups • Automatically and Dynamically Managed29
  30. 30. Coherence Recovery Example Distributed Topology • No in-flight operations lost • Some latencies (due to higher priority of recovery) • Reliability, Availability, Scalability, Performance are the priority • Degrade performance of some requests30
  31. 31. JPA with Coherence Cluster Node 1 Cluster Node N Application Logic Application Logic ... JPA JPA Coherence Read TX Commit Entities
  32. 32. TopLink Grid—Configurations• Grid Cache—Coherence as Shared (L2) Cache • Configurable per Entity type • Entities read by one grid member are put into Coherence and are immediately available across the entire grid• Grid Read • All supported read queries executed in the Coherence data grid • All writes performed directly on the database by TopLink (synchronously) and Coherence updated• Grid Entity • All supported read queries and all writes are executed in the Coherence data grid
  33. 33. Grid Cache (Cache Aside)• Reading: • Primary Key queries check JPA Application Coherence first. • If found in Coherence, Entity is returned. PK • If not found the database is Query queried. • Entities queried from database Insert/ are put() into Coherence and Update/ Query returned to the application. Delete• Writing: • All inserts, updates, and deletes are directed to the database • On successful commit, Coherence is updated
  34. 34. Grid Cache—Leveraging Cache• Cache is used when processing database results• EclipseLink extracts primary keys from results and checks cache to avoid object construction.• Even if a SQL query is executed, an object cache can still improve application throughput by eliminating object construction costs for cached Entities
  35. 35. Grid Read• All writes performed directly JPA Application on database.• Primary key queries result in get() on Coherence• JPQL queries, e.g., Select e from Employee E Query are translated to Filters and executed in Coherence• CacheLoaders should be configured to query database with PK query on cache miss Insert/ Update/ PK Delete Query
  36. 36. Coherence Cache Application Logic EntityManager Persistence Context EntityManagerFactory TopLink Grid Coherence
  37. 37. Coherence Cache Application Logic EntityManager Persistence Context EntityManagerFactory TopLink Grid Coherence Coherence
  38. 38. How is TopLink Grid different from Hibernate with Coherence?• Hibernate does not cache objects, it caches data rows in Coherence• Using Coherence as a cache for Hibernate • Every cache hit incurs both object construction and serialization costs • Worse, object construction cost is paid by every cluster member for every cache hit• Hibernate only uses Coherence as a cache—TopLink Grid is unique in supporting execution of queries against Coherence which can significantly offload the database and increase throughput
  39. 39. Summary• EclipseLink supports a unique range of strategies for scaling JPA applications• TopLink Grid provides: • An easy way for JPA developers to scale out their Java EE applications • JPA on the Grid functionality to support scaling JPA applications with Coherence • Support for caching Entities with relationships in Coherence
  40. 40. Q U E S T I O N S A N S W E R S
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×