Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EclipseLink/Examples/JPA/MetadataSource/PropertyOverrides
MetadataSource was extended to support properties overrides. To simply access properties file in persistence unit, specify in persistence.xml xml meta data source:
<property name="eclipselink.metadata-source" value="XML"/>
this of course could be combined with overriding mappings, too:
<property name="eclipselink.metadata-source" value="XML"/> <property name="eclipselink.metadata-source.xml.url" value="foo://bar"/>
Specify properties file name in the Java application:
Map properties = new HashMap(); properties.put("eclipselink.metadata-source.properties.file", "extension.properties"); JpaHelper.getEntityManagerFactory(em).refreshMetadata(properties);
extensions.properties file contains the new properties' values, for instance:
javax.persistence.jtaDataSource=MyJtaDataSource javax.persistence.nonJtaDataSource=MyNonJtaDataSource
After that the new EntityManagers created from this factory will use the properties specified in extension.properties file.
Alternatively to implement their own MetadataSource
<property name="eclipselink.metadata-source" value="mypackage.MyMetadataSource"/>
user need now to implement the new method getPropertyOverrides, too:
public class MyMetadataSource implement MetadataSource { @Override public XMLEntityMappings getEntityMappings(Map<String, Object> properties, ClassLoader classLoader, SessionLog log) { ... } @Override public Map<String, Object> getPropertyOverrides(Map<String, Object> properties, ClassLoader classLoader, SessionLog log) { ... } }