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: 
DanielSilva1
Advisor
Advisor

One customer was having a big problem with duplication of records (Violation of PRIMARY KEY constraint), when trying to add any purchase request via their HCPms offline native app for Android. For some reason, the device was not receiving an acknowledge from the backend saying that the flushed data had been committed. So, when another operation in the offline store was performed and a flush was called again, the duplication error happened again, because, for the offline store, the first purchase request had not been committed to the backend yet.


The reason behind this issue was incorrect understanding of how to properly setup and code for offline OData. The documentation provided was somewhat vague and has been improved due to this finding. For now, you can refer to the HCPms documentation which is very well explained: SAP HANA Cloud Platform Mobile Services. Please, remember that some other error would also have happened for an online app.


Different rewrite modes require different service root URLs in SMP and HCPms. The customer had set the Rewrite Mode field of the connection to the backend configuration to the Rewrite URL on Backend value, but had set the serviceRoot option of the OData Offline Store Options as if they had set the Rewrite Mode field of the connection to the backend configuration to the Rewrite URL on HANA Mobile Server value. Remember that the serviceRoot property of an offline store options structure identifies the root of an OData service.

OK, so let's understand what is the correct value for each Rewrite Mode option:



  • No Rewriting: "request and response messages are not modified; SAP HANA Cloud Platform mobile services passes messages directly between clients and the back end".

NOTE: "To enable applications using an external back end to run offline, you must select one of the rewrite options."


In Java code, the store options would look like the following for the Rewrite URL on Backend option:


ODataOfflineStoreOptions options = new ODataOfflineStoreOptions();
...
options.host = "myserver";
options.port = "8080";
options.serviceRoot = "http://myserver:8080/sap/opu/odata/sap/service";
...

In Java code, the store options would look like the following for the Rewrite URL on HANA Mobile Server option:


ODataOfflineStoreOptions options = new ODataOfflineStoreOptions();

...

options.host = "myserver";

options.port = "8080";

options.serviceRoot = "http://myserver:8080/<ApplicationID>";

...

1 Comment