The OData services created from JPA models using OData JPA Processor Library derives the names for its elements from Java Persistence Entity elements. These derived (default) names can be redefined using JPA EDM mapping models. JPA EDM Mapping model can be used to redefine:
Schema Namespace Name
Entity Type Names
Entity Set Names
Property Names
Navigation Property Names
Complex Type Names
The OData JPA Processor Library applies certain naming rules to derive the names for the above OData elements by default. Here are the rules:
Note: The names generated by applying the above rules can be overridden using JPA EDM Mapping models. JPA EDM mapping model can be maintained as an XML document according to the schema.
Pass the XML name into ODataJPAContext. In the method initializeODataJPAContext, pass the name of the XML document as shown below:
oDataJPAContext.setJPAEdmNameMappingModel(<mapping XML filename with XML extension>);
Compile, deploy and run the web application in a web server. A sample JPA EDM Mapping Model is provided as an example below:
<?xml version="1.0" encoding="UTF-8" ?> - <JPAEDMMappingModel xmlns="http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping"> - <PersistenceUnit name="salesorderprocessing"> <EDMSchemaNamespace>SalesOrderProcessing</EDMSchemaNamespace> - <JPAEntityTypes> - <JPAEntityType name="SalesOrderHeader"> <EDMEntityType>SalesOrder</EDMEntityType> <EDMEntitySet>SalesOrders</EDMEntitySet> - <JPAAttributes> <JPAAttribute name="soId">ID</JPAAttribute> <JPAAttribute name="netAmount">NetAmount</JPAAttribute> <JPAAttribute name="buyerAddress">BuyerAddressInfo</JPAAttribute> </JPAAttributes> - <JPARelationships> <JPARelationship name="salesOrderItem">SalesOrderLineItemDetails</JPARelationship> <JPARelationship name="notes">NotesDetails</JPARelationship> </JPARelationships> </JPAEntityType> - <JPAEntityType name="SalesOrderItem"> <EDMEntityType>SalesOrderLineItem</EDMEntityType> <EDMEntitySet>SalesOrderLineItems</EDMEntitySet> - <JPAAttributes> <JPAAttribute name="liId">ID</JPAAttribute> <JPAAttribute name="soId">SalesOrderID</JPAAttribute> </JPAAttributes> - <JPARelationships> <JPARelationship name="salesOrderHeader">SalesOrderHeaderDetails</JPARelationship> <JPARelationship name="materials">MaterialDetails</JPARelationship> </JPARelationships> </JPAEntityType> </JPAEntityTypes> - <JPAEmbeddableTypes> - <JPAEmbeddableType name="Address"> <EDMComplexType>AddressInfo</EDMComplexType> - <JPAAttributes> <JPAAttribute name="houseNumber">Number</JPAAttribute> <JPAAttribute name="streetName">Street</JPAAttribute> </JPAAttributes> </JPAEmbeddableType> </JPAEmbeddableTypes> </PersistenceUnit> </JPAEDMMappingModel>
Copyright © 2013-2021, The Apache Software Foundation
Apache Olingo, Olingo, Apache, the Apache feather, and
the Apache Olingo project logo are trademarks of the Apache Software
Foundation.