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

Difference between revisions of "EclipseLink/Examples/JPA/MetadataSource"

(New page: = EclipseLink JPA MetadataSource = Starting with [http://www.eclipse.org/eclipselink/releases/2.3.0.php EclipseLink 2.3.0] developers can now build solutions with EclipseLink JPA storing ...)
 
 
Line 1: Line 1:
 
= EclipseLink JPA MetadataSource =
 
= EclipseLink JPA MetadataSource =
  
Starting with [http://www.eclipse.org/eclipselink/releases/2.3.0.php EclipseLink 2.3.0] developers can now build solutions with EclipseLink JPA storing mapping information outside the application and can have it retrieved when the application's persistence unit is being created.
+
Starting with [http://www.eclipse.org/eclipselink/releases/2.3.0.php EclipseLink 2.3.0] developers can now build solutions with EclipseLink JPA storing mapping information outside the application and can have it retrieved when the application's persistence unit is being created. This feature can be used for any mapping customization including [[EclipseLink/Examples/JPA/Extensibility | Extensible JPA Entities]].
  
 
== The Basics ==
 
== The Basics ==
Line 42: Line 42:
 
</source>
 
</source>
  
 +
=== 2. Mapping Server ===
 +
 +
The mapping server needs to provide URL access to a mapping file. This can be done using many different web technologies ranging from static file serving to a rich server based solution with its own persistent store of XML files or mapping information stored in a more granular form and put together into mapping documents on demand.
 +
 +
The MySports example referenced below implements a JAX-RS based solution with the mapping extensions stored as separate JPA entities themselves and combined together on demand to create a tenant specific mapping override file with that tenant's extension mappings.
  
 
== Learn More ==
 
== Learn More ==

Latest revision as of 08:12, 13 June 2011

EclipseLink JPA MetadataSource

Starting with EclipseLink 2.3.0 developers can now build solutions with EclipseLink JPA storing mapping information outside the application and can have it retrieved when the application's persistence unit is being created. This feature can be used for any mapping customization including Extensible JPA Entities.

The Basics

In order to make use of this capability you must

  1. Configure the client persistence unit
  2. Configure the server

1. Client PU

The external storage of mappings can be as simple as making the eclipselink-orm.xml file with the additional mapping information available on a web server as a file but can be more complex involving a server process that stores the mapping information and supports dynamically updating this information.

If you simply want to access the mapping file at a fixed URL for your persistence unit you can use:

<property name="eclipselink.metadata-source" value="XML"/>
<property name="eclipselink.metadata-source.xml.url" value="foo://bar"/>

If however you are building a more complex solution involving a calculated location based on application context you will need to implement the MetadataSource interface. This could be used to have tenant specific extensions in a Multitenant application. To configure this you will need to setup the properties as:

<property name="eclipselink.metadata-source" value="mypackage.MyMetadataSource"/>
<property name="eclipselink.metadata-source.xml.url" value="foo://bar"/>

In the MySports example application a JAX-RS (RESTful) service is built that returns the mapping file per tenant. This is done like:

public class AdminMetadataSource extends XMLMetadataSource {
 
    @Override
    public XMLEntityMappings getEntityMappings(Map<String, Object> properties, ClassLoader classLoader, SessionLog log) {
        String leagueId = (String) properties.get(LEAGUE_CONTEXT);
        properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_URL, "http://foo.bar/rest/" + leagueId + "/orm");
        return super.getEntityMappings(properties, classLoader, log);
    }
}

2. Mapping Server

The mapping server needs to provide URL access to a mapping file. This can be done using many different web technologies ranging from static file serving to a rich server based solution with its own persistent store of XML files or mapping information stored in a more granular form and put together into mapping documents on demand.

The MySports example referenced below implements a JAX-RS based solution with the mapping extensions stored as separate JPA entities themselves and combined together on demand to create a tenant specific mapping override file with that tenant's extension mappings.

Learn More

Copyright © Eclipse Foundation, Inc. All Rights Reserved.