Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
rajnish_tiwari2
Advisor
Advisor


This is the continuation of previous blog (blog series), In this blog will be explaining about JPA mapping and how columns name which can be renamed and column's join can be renamed as well as how class name can be manipulated in xml.

 

Introduction:

 

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:




  1. Schema Namespace Name is derived from Java Persistence Unit Name.

  2. Entity Type Names are derived from Java Persistence Entity Type Names.

  3. Entity Set Names are derived from EDM Entity Type Names suffixed with character "s".

  4. Property Names are derived from Java Persistence Entity Attribute Names. The initial character in the property name is converted to an upper-case character.


Steps to modify the Metadata

  1. Create a JPA EDM Mapping model XML according to the schema given below. In the XML, maintain the mapping only for those elements that needs to be redefined. For example, if JPA Entity Type A's name has to be redefined, then maintain an EDM name for the same.

  2. Deploy the JPA EDM Mapping model XML file in the root directory of your web application archive (store it in the same directory as 'WEB-INF').

  3. 3. Pass the XML name into ODataJPAContext. In the method initializeODataJPAContext, pass the name of the XML document as shown below:


 



 

As you can observe below that persistence unit name definition is must and it should be maintained across the application,


Compile, deploy and run the web application in a web server. A sample JPA EDM Mapping Model is provided as an example below:

 



 

So in the above blog, it has been explained that how JPA mapping can be creates as well as attributes name can be manipulated based on the requirement, In the next blog i.e. Part 5 I will be explaining about the Debugging implementation in olingo 2.0 OData services.

 

3 Comments
0 Kudos
Hi Rajnish,

How to mention the function imports in this JPA EDM Model mapping?

 

Regards,

Ganesh Gangatharan K
rajnish_tiwari2
Advisor
Advisor
0 Kudos

Hi Ganesh,

I have not implemented the function import but you can do in this way

// sample code to set the function import
JPAEdmMapping mapping = new JPAEdmMappingImpl();
((Mapping) mapping).setInternalName(method.getName());
mapping.setJPAType(method.getDeclaringClass());
functionImport.setMapping((Mapping) mapping);
functionImport.setHttpMethod(edmAnnotationFunctionImport.httpMethod().name().toString());
buildEdmReturnType(functionImport, method, edmAnnotationFunctionImport);

xml syntax for funtion import
<EntitySet Name="EntityName" EntityType="entityType" />
<FunctionImport Name="FunctionImport" EntitySet="EntitySet" ReturnType="Collection(entitycollection)" m:HttpMethod="GET" />

 

You can use this approach to use the function import in order to override the function import method.

Thanks, Rajnish

0 Kudos
How can we get the original name for an extended name? I mean assume we have `IconId` instead of  `Icon`! Now how can I reach the original name when I have access to `IconId` ?