Skip to Content
Author's profile photo Rajnish Tiwari

SLN Spotlight_SAP Labs India: adding custom annotation and labels to metadata

This is the continuation of previous blog (blog series), In this blog series will be explaining about adding custom annotation and labels into ODATA metadata, but in Olingo 2.0 anytype of Aggregation is not possible.



In order to add new annotation into the metadata to any of the Entity class or calculation view then, we have to extend the JPAEdmExtension class and create a Java class by implementing the interface org.apache.olingo.odata2.jpa.processor.api.model to register the annotated Java methods. Below metadata of Employee and Orders Entity class info, before the annotation addition you need to include below set of code in SampleCustomOdataJpaServiceFactory class,

  • oDataJPAContext.setJPAEdmExtension((JPAEdmExtension) new CustomAnnotationProcessor());



And in CustomAnnotationProcessor class override the extendJPAEdmSchema method as shown below, In below sample code I have just added the generic annotation on all the columns, if required you  can added different annotation for different columns as well as for class level also.





Now when you check the metadata before annotation addition,





Now below metadata shows after adding annotation at entity level by implementing the JPAEdmExtension class



In this blog it has been explained that how custom annotation can be added in columns metadata of ODATA.

In next blog .i.e. Part4, how JPA mapping can be redefined.





Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Treasa PA
      Treasa PA

      Hi Rajnish,

      I'm also trying out the sap annotations. In the code snippet for adding annotation to the entity properties, the value for prefix of the attribute is set as "sap", and the value for name is set as "sap:label". However in the metadata, it gets displayed as "sap:label". Is the prefix value ignored even though it is set?

      Kind Regards,
      Treasa PA

      Author's profile photo Rajnish Tiwari
      Rajnish Tiwari
      Blog Post Author

      Hi Treasa,

      Its not ignored, if prefix is not added as sap then value can not to be set as sap:label. i was facing some issue in adding the tags so i have to set prefix as “sap” and label as “sap:label”

      Moreover it expects that before : (colon) whatever value we are adding the same value has to added in prefix also.