Skip to Content
0
Apr 25, 2019 at 11:45 AM

OData V2: oModel.update()-Method always uses HTTP-Method "POST" instead of "PUT"

4316 Views Last edit Apr 25, 2019 at 12:42 PM 7 rev

Hello Community,

I'm working on a simple webmask which allows a user to do CRUD operations on a game library (which contains some names of Computer Games).

Technical Background:

  • IDE: SAP Web IDE for HANA 2 SPS 03 Patch 0 ( Build 4.3.23 )
  • SAPUI5 Frontend
  • HANA Database
  • OData Webservice ( Table: {#ID [Int, Primarykey Identity], GAME [String]} ) - Uses XSJS

Problem Description:

While Read, Insert and Delete work as expected, I have trouble using the update-Method for the oModel which is based on my xsodata service that has been configured in the manifest.json.

The situation: Whenever I fire the oModel.update call, the update does not use HTTP-method "PUT", but "POST" instead. Of course the Webservice then returns the following error message:

The URI is not valid for POST operation. The URI must point to an entity set for POST operations.

My request:

POST /xsodata/getGames.xsodata/games(17) HTTP/1.1
Content-Length: 35
Host: xsa.realcore.local:51059
Content-Type: application/json
{
  "ID": 17,
  "GAME": "Quake 2"
}

Of course this is wrong, but I do not have any influence on the http method that has been configured to the update-method so far:

this._gameService = this._ownerComponent.getModel("games"); 
this._gameService.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay); 
this._gameService.setRefreshAfterChange(true);

var that = this; 
this._gameService.setHeaders({
	"content-type": "application/json;charset=utf-8"
});
this._gameService.update("/games("+gameObjectToSave.ID+")",
	gameObjectToSave, {
	success: function() {
		that._readGames(); 
		that._oGameLibrary.refresh();	
	}, 
	error: function(e) {
		console.log(e); 
	} 
});

Manifest.json:

"dataSources": {
	"games": {
		"uri": "/xsodata/getGames.xsodata",
		"type": "oData",
		"settings": {
			"odataVersion": "2.0"
		}
	}
}
....
"games": {
	"dataSource": "games", 
	"type": "sap.ui.model.odata.v2.ODataModel", 
	"preload": true,
	"settings": {
	  "odataVersion": "2.0", 
	  "useBatch" : false
	}
}
....


Possible, but bad way to solve this:

One way to solve this issue is to use a deprecated version of the ODataModel:

"type": "sap.ui.model.odata.ODataModel", 

(Infos about the deprecation can be found in the api-documentation of openui5.)

But I would like to use ODataModel Version 2. In V1 it somehow works and the update is using the "PUT" method as expected.

Any ideas?

Kind regards

Marc