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/UserGuide/sandbox/gelernter/External Mappings"

m
m
Line 17: Line 17:
 
{{EclipseLink_NewIn
 
{{EclipseLink_NewIn
 
|version=2.3}}
 
|version=2.3}}
 +
<br/>
 
<br>
 
<br>
<br>
+
 
 
You can store mapping information using a MetadataSource external to the running application so that mapping overrides and extended mappings can be dynamically integrated into deployed applications. The mapping information is retrieved when the application's persistence unit is being created. This feature can be used for any mapping customization including [[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Extensible_Entities| Extensible JPA Entities]].
 
You can store mapping information using a MetadataSource external to the running application so that mapping overrides and extended mappings can be dynamically integrated into deployed applications. The mapping information is retrieved when the application's persistence unit is being created. This feature can be used for any mapping customization including [[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Extensible_Entities| Extensible JPA Entities]].
  

Revision as of 14:56, 30 June 2011

EclipseLink JPA

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source

Elug api package icon.png Key API

  • []

Elug example icon.png Examples

  • [[]]

******SANDBOX VERSION******

Externalized Mappings

EL NewIn.png New in version 2.3.



You can store mapping information using a MetadataSource external to the running application so that mapping overrides and extended mappings can be dynamically integrated into deployed applications. The mapping information is retrieved when the application's persistence unit is being created. This feature can be used for any mapping customization including Extensible JPA Entities.

To configure externalized mapping, you must:

  1. [# Configuring the Persistence Unit|Configure the client persistence unit]
  2. [# Configuring the Server|Configure the server]

Configuring the Persistence Unit

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);
    }
}

Configuring the Server

The server must provide URL access to a mapping file. This can be done using a number of Web technologies, including:

  • Static file serving
  • Server-based solution with its own persistent store of XML files or mapping information stored in a 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