Skip to Content
0

HANA XSODATA no update possible

May 19, 2017 at 07:48 PM

464

avatar image

I am on HANA 2.0 SP01

In my CDS i have a key field with a generated key:

  key ID            : Integer generated always as identity(start with 10000 increment by 1  maxvalue 19999 );

My odata service is as simple as possible:

service {
  "kema.opdracht" as "opdrachten" ;
}

I would expect the CREATE/POST to work but when testing from Postman I get an error

{"error":{"code":500,"message":{"lang":"en-US","value":"INSERT, UPDATE and UPSERT are disallowed on the generated field: cannot insert into generated identity column field ID: line 1 col 29 (at pos 28)"}}}

It looks like xsodata cannot handle CDS entity element modifiers like 'generated always.... Is my assumption true? Has anyone else encountered this?

Some help will be appreciated.

xsa
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Thomas Schmidt Jul 13, 2017 at 10:22 PM
0

I faced the same problem while trying to update oData V2 services build on HANA CDS entities with a key like this :

 key id     : entityID generated always as identity(start with 1 increment by 1);

here are the oData POST test cases with an empty entity hana cds table.

case 1 without id in request JSON:

INSERT, UPDATE and UPSERT are disallowed on the generated field: cannot insert into generated identity column field id

case 2 with id and some random number

INSERT, UPDATE and UPSERT are disallowed on the generated field: cannot insert into generated identity column field id

case 3 with id in request JSON and as value null:

The serialized resource has an missing value for member id

the solution to this is a xsjslib script via the odata create which makes the insert without he id ....

found here: https://blogs.sap.com/2015/03/06/odata-service-definition-xsodata-for-tables-with-an-identity-column/

Show 1 Share
10 |10000 characters needed characters left characters exceeded

I agree that this is a weird implementation, I had to use xsjslib as well. But, I'd also suggest you to change the "after" table as well:

const updatePayloadStmt = params.connection.prepareStatement('UPDATE "' + after + '" SET "id" = ? WHERE "id" = ?');
updatePayloadStmt.setInteger(1, newId);
updatePayloadStmt.setInteger(2, oldId);
updatePayloadStmt.executeUpdate();

In my case I use HANA 1.0, where the keyword IDENTITY is not supported. That is why I had to ask the SEQUENCE directly to generate the next key value (newId), and I update the old ID with the new one.

This is helpful, because my POST request (with INSERT) returns the newly created object, and the ID field is the real value rather than what I have just sent.

0