3. Eclipse Persistence Services
“EclipseLink”
Java SE Java EE OSGi Spring ADF
JPA MOXy EIS SDO DBWS
Eclipse Persistence Services Project
(EclipseLink)
Databases XML Data Legacy Systems
5. Significance of EclipseLink
• First comprehensive open source persistence solution
• Object-Relational and much more
• Based upon product with 12 years of commercial
usage
• Shared infrastructure
• Easily share the same domain model with multiple
persistence technologies
• Leverage metadata for multiple services
• Important part of the GlassFish and Eclipse
Ecosystems
7. Caching
• Hold objects in-memory to avoid unnecessary
database trips and object construction
• Cache manages “identity” to support bidirectional and
cyclical relationships
• Flexible caching options ensure that you get
maximum performance
• Numerous locking, refreshing, and synchronization
options are available to minimize cache staleness
• Queries can be run in-memory only against the cache
• Cache Coordination supports clustering
10. Minimize stale cache
• Configure the cache relative to application data’s
usage
• Is the data shared between users/processes?
• Is the data volatile?
• Only through JPA application?
• Through direct DB modification?
• Ensure you protect any data that can be concurrently
modified with a locking strategy
• Must handle optimistic lock failures on flush/commit
• Use query refreshing to minimize optimistic lock
failures
13. Leveraging the Shared Cache: Writing
EntityManagerFactory
L2 Cache Connection Pool
Connection
Connection
Connection
Connection
Connection
14. Advanced Mappings
• @Converter
• @BasicMap and @BasicCollection
• Mapping to database structures
• @StructConverter – Structs, ADTs
• XML types, PL/SQL Records
• Mapping features
• Private Owned
• Join/Batch Fetch
• Returning
15. Advanced Mapping Example
@Entity
@Cache(type=SOFT_WEAK, coordinationType=SEND_OBJECT_CHANGES)
@Converter(name=“money”, converterClass=MoneyConverter.class)
@OptimisticLocking(type=CHANGED_COLUMNS)
public class Employee {
@Id
private int id;
private String name;
@OneToMany(mappedBy=“owner”)
private List<PhoneNumbers> phones;
@Convert(“money”)
private Money salary
…
}
16. Advanced Querying
• Support for supplying customizing queries
• Native SQL
• @NamedStoredProcQuery
• Graph Loading Optimizations
• Join and Batch Fetch – multi-level
• Cache Usage: In-memory
• Result caching
17. Transactions
• Java apps typically support many clients sharing
small number of db connections
• Ideally would like to minimize length of transaction on
database
Begin Txn
Time
Begin Txn
Commit Txn
Commit Txn
18. Transaction Features
• Minimizes database interactions
• Only the minimal updates are sent to the database
• Respect database integrity
• Orders INSERT, UPDATE and DELETE statements
• JTA and RESOURCE_LOCAL support
• Attribute-level change tracking
• EntityManager flush SQL prior to commit
• Bulk Update and Delete
• Cached entities effected
19. Concurrency Protection - Locking
• Optimistic concurrency included in JPA 1.0, but no
support for pessimistic locking is specified
• EclipseLink has advanced optimistic locking
strategies
• Numeric, Timestamp, All fields, Selected fields, Changed field
• EntityManager lock() method can be used with
optimistic locking, and error handling
• EclipseLink supports pessimistic locking through
query hints
query.setHint(PESSIMISTIC_LOCK, LockNoWait);
20. Weaving
• EclipseLink makes use of Weaving (ASM) to
introduce additional functionality into the JPA entity
classes
• Needed for M:1 and 1:1 lazy fetching
• Integrated with Java EE compliant App Servers and Spring
2.0
• Available for Java SE using JDK/JRE’s –javaagent:
• Optional
• Static weaving also supported
• Weaving of .class files before deployment
28. DDL Generation
• Standard enables it but does not currently dictate that
providers support it
• Mapping metadata specifies how DDL should be
generated
• Vendors may offer differing levels of support,
including:
• Generating DDL to a file only
• Generating and executing DDL in DB
• Dropping existing tables before creating new ones
31. Descriptor & Session Customizers
public class MySessionCustomizer
implements SessionCustomizer {
public void customize(Session session) {
session.setProfiler(new PerformanceProfiler());
}
}
public class MyDescriptorCustomizer
implements DescriptorCustomizer {
public void customize(ClassDescriptor desc) {
desc.disableCacheHits();
}
}
32. Performance and Tuning
• Highly configurable and tunable
• Guiding principle – minimize and optimize database
interactions
• No two applications are the same, EclipseLink allows for
decisions on what specific behavior needs to be configurable
depending on situation
• Flexibility of EclipseLink allows efficient business
models and relational schemas to be used
• Leverages underlying performance tuning features
• Java, JDBC and the underlying database technology
• Batch Writing
• Parameter Binding
• Statement Caching
33. Performance and Tuning
Minimal Writes, Updates
“Just in Time” reading
Batch Reading, Writing
Automatic change detection
SQL ordering
Caching policies and sizes
Transformation support
Parameterized SQL (binding)
Existence checks
Pre-allocation of sequence
Stored procedures numbers
Statement Caching
Cache Coordination
Scrolling cursors
Optimistic, Pessimistic locking
Projection Queries
Joining object retrieval
Partial Attribute Queries optimization
In memory querying
Dynamic queries
AND MUCH MORE!
34. EclipseLink Status
• Incubating Technology Project
• Initial contribution of Oracle TopLink complete
• Full documentation available on Wiki
• Producing Monthly Milestone builds
• Milestones included in GlassFish V3 Milestones
• 1.0 release planned for July 2008
• JPA 1.0, SDO 2.1, JAXB
• Simplified XML and annotation config of advanced features
• Packaged for Java SE/EE and OSGi bundles
• Beyond 1.0
• JPA 2.0 (Reference Implementation)
• Database Web Services
• Data Access Service (DAS) 1.0
• and much more …
35. Getting Started with EclipseLink JPA
• EclipseLink Project
http://www.eclipse.org/eclipselink
Eclipse newsgroup: eclipse.technology.eclipselink
• GlassFish V3
https://glassfish.dev.java.net/
• Open Source JPA Tools
• NetBeans—http://www.netbeans.org
• Dali JPA Tools—http://www.eclipse.org/dali