Introduction to JPA and TopLink Grid
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Introduction to JPA and TopLink Grid

on

  • 2,973 views

 

Statistics

Views

Total Views
2,973
Views on SlideShare
2,459
Embed Views
514

Actions

Likes
1
Downloads
67
Comments
0

6 Embeds 514

http://blogs.oracle.com 498
http://www.javaoracleblog.com 8
http://www.hanrss.com 3
http://feeds.feedburner.com 3
http://flavors.me 1
http://prsync.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Introduction to JPA and TopLink Grid Presentation Transcript

  • 1. <Insert Picture Here>TopLink Grid: Scaling JPA applications withCoherenceAndrei Cristian NiculaeTechnology Presales Consultant
  • 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. 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. 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. 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. 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. 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. 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. JPA Object-Relational Mappings• Core JPA Mappings • Id • Basic • Relationships • OneToOne • ManyToOne • OneToMany • ManyToMany • And more…• Annotations and/or XML
  • 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. 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. 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. 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. Example JPA Client Code…
  • 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. 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. Application Application Application JPA Application Application Application Application Application JPA Application Application Scaling Java Persistence... Application Application Application JPA Application Application
  • 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. 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. Strategy 1: Disable Shared Cache Application Logic Application Logic EntityManager EntityManager Persistence Persistence Context ContextEntityManagerFactory EntityManagerFactory
  • 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. Strategy 2: Cache Coordination Application Logic Application Logic EntityManager EntityManager Persistence Persistence Context ContextEntityManagerFactory EntityManagerFactory Shared Cache Shared Cache Coordination Cache
  • 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. 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. 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. TopLink Grid with Coherence Cache Application Logic Application Logic EntityManager EntityManager Persistence Persistence Context ContextEntityManagerFactory EntityManagerFactory Coherence
  • 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. 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. 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. 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. JPA with Coherence Cluster Node 1 Cluster Node N Application Logic Application Logic ... JPA JPA Coherence Read TX Commit Entities
  • 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. 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. 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. 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. Coherence Cache Application Logic EntityManager Persistence Context EntityManagerFactory TopLink Grid Coherence
  • 37. Coherence Cache Application Logic EntityManager Persistence Context EntityManagerFactory TopLink Grid Coherence Coherence
  • 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. 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. Q U E S T I O N S A N S W E R S