Skip to Content

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:

 

/wp-content/uploads/2016/10/21_1042984.png

 

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:

 

/wp-content/uploads/2016/10/22_1042989.png

 

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.

 

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply