Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Development/SDO-JPA

< EclipseLink‎ | Development
Revision as of 14:04, 10 December 2008 by Douglas.clarke.oracle.com (Talk | contribs) (Querying)

EclipseLink Incubator: SDO Data Access Service with JPA

The work is being developed within the EclipseLink/Development/Incubator and is being tracked by bug 258057.

This incubator is intended to illustrate how SDO can be used with JPA to provide relational database access to data exposed as SDO DataObjects. This functionality bridges SDO, JPA, and MOXy components and may also result in the generation of some additional utilities to simplify development tasks and tooling support.

Incubator Exit Criteria

This incubator feature is intended to facilitate rapid development and interaction with consumers. Once each usage scenario is validated with the consumers and the necessary testing is in place the functionality will be migrated back into the main components (SDO, MOXy, JPA, & Core) as well as the necessary test cases being migrated into the corresponding projects.

This incubator feature will continue to evolve functionality until all of the consumer required use cases surrounding SDO usage with JPA have been addressed.

Use Cases

There are several options for using SDO with JPA:

  1. SDO DataObjects wrapping JPA entities. The XSD and DataObject model defined by JAXB mappings on the JPA entities
  2. JPA Mapping of SDO DataObjects

1. SDO DataObjects wrapping JPA entities

In this use case a developer wishes to expose their JPA model as an SDO DataObject model (static or dynamic). The JPA entities are mapped to a XSD through JAXB mappings.

  1. In this use case the developer defines the mapping from the JPA domain model (POJOs) to an XML schema (XSD) using JAXB mappings (annotations or EclipseLink native OXM).
  2. The XSD is then generated using the JAXB Java-XML Compiler (JXC)
  3. The SDO Data Object model is now implicitly define through the use of the generated XSD. If the service developer wishes to use a static DataObject model they can optionally use the SDO compiler to generate this model based on the XSD.

1.1. SDO Bootstrapping

When the application needs to interact with the JPA backed SDO model the service being developed must bootstrap the SDO context. In general SDO usage the context is initialized using something like:

InputStream xsdInputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("Customer.xsd");
XSDHelper.INSTANCE.define(xsdInputStream, null);

When using JPA entities behind the SDO model the service developer will also need to provide metadata concerning the JAXB mappings and the underlying JPA mapping metadata.

Querying

When developing a service that will return SDO DataObject instances from the relational database the developer will issue queries against the database using JPA (PK Find, JP QL or Native ORM queries in JPA 1.0). The resulting entities will then be wrapped by DataObject using a provided helper class.

EntityManagerFactory emf = SdoJpaHelper.getEntityManagerFactory(sdoContext);
EntityManager em = emf.createEntityManager();
 
List<MyEntity> entities = em.createQuery("SELECT e FROM MyEntity e WHERE ...").getResultList();
 
List<DataObject> dataObjects = SdoJpaHelper.wrap(sdoContext, entities);

Creating (JPA persist)

Updating (JPA merge)

Deleting (JPA remove)

Scenario: WEB Service 1. Receives data graph of SDO objects 2. Unmarshalls data graph into Eclipse Link objects including change summary 3. Should update changes from data graph in database using EclipseLink JPA

Back to the top