spring-boothibernatejpaolingo

Get the JPA filed name when we extended the metadata in olingo


Here it has been explained how can we extend metadata of an oData service in olingo V2.

<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>

This small snippet of code explained how I can change a JPA entity field's name buyerAddress to the new name BuyerAddressInfo.

Now the question is how can I access to the original name when I have access to BuyerAddressInfo and ODataJPAContext?


Solution

  • I discovered following method from here. By this method I can access BuyerAddressInfo by having buyerAddress and JPA Entity name!

    import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
    import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
    // .....
    JPAEdmMappingModelAccess jpaEdmMappingModelAccess = 
    ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAEdmMappingModelAccess(oDataJPAContext);
    jpaEdmMappingModelAccess.loadMappingModel();
    String newName = jpaEdmMappingModelAccess.mapJPAAttribute("SalesOrderHeader", "SalesOrderHeader"));
    

    However what I am looking for is exactly vice versa! Therefore at the moment I use a Map and collect all the pairs and each time I iterate over them!