260 likes | 459 Vues
Eclipse JPA. Gordon Yorke EclipseLink Architecture Committee Member, EclipseLink Core Technical Lead, JPA 2.0 Expert Group Member gordon.yorke@oracle.com. What you will learn. Eclipse Persistence Services Project (EclipseLink) Components Focus on EclipseLink JPA
E N D
Eclipse JPA Gordon Yorke EclipseLink Architecture Committee Member, EclipseLink Core Technical Lead, JPA 2.0 Expert Group Member gordon.yorke@oracle.com
What you will learn • Eclipse Persistence Services Project (EclipseLink) • Components • Focus on EclipseLink JPA • Constructing a Persistence Unit • Developing with Dali • Deployments • Java SE, Java EE • Usage for RCP • EclipseLink Extensions
Eclipse Persistence Services • Eclipse runtime project • Nicknamed “EclipseLink” • Currently Incubating in Technology Project
What is EclipseLink • Based upon product with 12 years of commercial usage • First comprehensive open source persistence solution • EclipseLink JPA: Object-Relational • EclipseLink MOXy: Object-XML • EclipseLink SDO: Service Data Objects • EclipseLink EIS: Non-Relational using JCA • EclipseLink DBWS: Database Web Services
EclipseLink… • Shared infrastructure • Easily share the same domain model with multiple persistence technologies • Leverage metadata for multiple services • Providing enterprise data access and manipulation services to the Eclipse Ecosystem
XML Relational Databases Java SE, Java EE, SCA, Spring, OSGi JPA MOXy SDO DBWS EIS Eclipse Persistence Services (EclipseLink) JCA JDBC Packaged Apps Legacy Systems
Why EclipseLink JPA • JPA 1.0 compliant implementation • JPA 2.0 in development • Any JDBC/SQL compliant database • Database specific support for Oracle, Derby, MySQL, SQLServer, PostgreSQL and more. • Extensible and pluggable • Key infrastructure: • Query Framework, Mapping, … • many valuable advanced features • Caching, locking, dynamic enhancement (weaving) …
The JPA Specification • Simple configuration by exception • Extensive use of annotations • XML configuration available
ORM • Mappings • @Embeddables • multiple objects but data in same table • @Basic/@Id • Simple types mapping to single columns (ie. int, String) • @Lob • Binary based data (ie. Images) • @OneToOne, @ManyToOne • References to single target object. • @OneToMany, @ManyToMany • Collections and Maps • Class Inheritance • All classes in single table • Extended fields in separate tables
EntityManager • Contains the lifecycle APIs for the Entities • persist(), remove(), merge() • Contains management APIs for local transactions • getTransaction().begin(), getTransation().rollback(); • Contains management APIs for Persistence Context • clear() • Source for Queries • createQuery(), createNativeQuery(), find(), refresh() • Optimistic database locking • lock() • Central interface point for JPA
Persistence Context • Set of objects tracked for changes by Persistence Provider • Objects enter Persistence Context through EntityManager APIs • Has two life expectancies • transactional – entities are no longer tracked at end of transaction • extended – entities are tracked for life of Persistence Context unless cleared. • Persistence Context ≈ EntityManager • Except transactional PC will be propagated to multiple EMs within Container Managed environment • Changes will be written at end of transaction or on ‘flush’ call.
Queries • Dynamic or statically defined (named queries) • Criteria using JP QL (object based query language) • Native SQL support (when required) • Named parameters bound at execution time • Pagination and ability to restrict size of result • Single/multiple-entity results, data projections • Bulk update and delete operation on an entity • Standard hooks for vendor-specific hints
How to use it • Create Entities and Map • Simple POJOs • annotations or XML • Database can be pre-existing • Generate table definitions later • Package into Persistence Unit • Lots of options • Easiest into .jar • OSGi bundle support in development • Dali • Tooling for mapping and packaging persistence unit
The Persistence Unit .jar • Domain model • POJOs with or without annotations • Each entity must be designated as such and must have a PK defined. • META-INF/persistence.xml • Deployment configuration • Optional xml based mapping config (META-INF/orm.xml) • Can override annotations or provide full mapping config • Datasource name or JDBC connection properties • eclipselink.jdbc.driver, eclipselink.jdbc.connection-url • Entities to check for annotations
Java SE vs Java EE • Java SE deployment • Application managed EntityManagers • Local transactions • Persistence Context always ‘extended’ • Java SE bootstrapping APIs • -javaagent jvm argument for dynamic weaving • Java EE • Container managed EntityManager • PersistenceContext JTA transaction scoped or ‘extended’ • @PersisteneContext annotation for injection • Application Managed EntityManager • PersistenceContext always extended • JTA though ‘joinTransaction’ APIs • Dynamic weaving automatic
Inside Eclipse Rich Client • Referenced library or OSGI • OSGi EclipseLink bundles in development • http://wiki.eclipse.org/EclipseLink/Development/OSGi_Proof_of_Concept • Application managed EntityManagers • Local transactions • Persistence Context always ‘extended’ • Java SE bootstrapping APIs • Static weaving
Demo • Persistence Enable a Rich Client through bundles • Tools, • Dali • EclipseLink • Troubleshooting • Check that the Persistence Unit Bundle is included in your launch • Dali sets Persistence Unit name to project name by default make sure it matches the name in ComicsModel.java
EclipseLink JPA Extensions • Weaving • Lazy loading all non PK fields • Performance options - change tracking, batch writing, batch reading • Mappings • @BasicMap, @BasicCollection, @PrivateOwned, @JoinFetch • @Converter, @TypeConverter, @ObjectTypeConverter • @NamedStoredProcedureQuery • IN/OUT/INOUT parameters, multiple cursor results • Extensions supported through annotations and XML • Query hints • refreshing, locking, parameter binding, database platform hints …
Extensions - Locking • Data Locking policies • Optimistic: Numeric, Timestamp, All fields, Selected fields, Changed field • Pessimistic
Extensions - Entity Caching • Entity caching • L2 shared across transactions/users • Coordination in a clustered deployment • Application specific configuration • Caching: per Entity or per Persistence Unit • eclipselink.cache.shared(default|<entity>) • Cache Type and Size: Weak, Soft-Weak, Full, None* • eclipselink.cache.type(default|<entity>) • Expiration/Invalidation • Time to live, Time of day, API • Coordination (cluster-messaging) • Messaging: JMS, RMI, RMI-IIOP, … • Mode: SYNC, SYNC+NEW, INVALIDATE, NONE
Performance and Tuning • Highly configurable and tunable • Principle: minimize and optimize database calls • Enable application specific tuning • Flexibility allows efficient business models and relational schemas to be used • Leverages underlying performance tuning features • Java, JDBC and the underlying database technology • Batch Reading, Batch Writing, Joined Reading, etc…
DEMO • Extensions in action
EclipseLink in the Eclipse Ecosystem • Provide an Eclipse persistence solution easily consumable by any project • Storage of metadata in RDBMS, XML, EIS • XML Messaging infrastructure • Eclipse Projects • Dali JPA Tooling Project • Teneo to use EclipseLink for EMF model persistence • Maya for storage of deployment configuration • SOA Project for EclipseLink SDO
Where are we going? • Delivery of 1.0M5-incubation milestone • 1.0 Release Planed for June 2008 • Specifications: JPA2.0, JAXB 2.0, SDO 2.1 • OSGi packaging and usage examples • Database Web Services (DBWS) • Data Access Service (DAS) - SDO with JPA
How can you get involved? • Users • The 1.0M5-incubation milestone is now available • Try it out and provide feedback • File bug reports and feature requests • Contributors • Contribute to roadmap discussions • Bug fixes • Committers • Very interested in growing committer base
More Information • www.eclipse.org/eclipselink • Newsgroup: eclipse.technology.eclipselink • Wiki: wiki.eclipse.org/EclipseLink • Mailing Lists: • eclipselink-dev@eclipse.org • eclipselink-users@eclipse.org • Blogs • Committer Team blog: eclipselink.blogspot.com