Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search


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 {
    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, "" + 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

Back to the top