Skip to Content

Help needed to understand commit, createEntry, submitEntry and GroupId's for deep entity sets?

Nov 01, 2016 at 12:43 AM


avatar image

To start with: Imagine you have a Fiori app that allows you to create a customer. You first enter a name, then create a billing address, then create a shipping address. When you have all the information, you press "Save". It's at this point it is written to the database.

From an entity perspective, you have a Customer entity, and an Address entity with a 1..n relationship.

For this scenario in the past, I've been using create deep entities for this however, I've also been using it for updates to get the required single commit. Now while this works just fine, I believe I'm doing this in a way that may be unsupported in the future, and want to validate my understanding of the right way to do this.

So is this the right way?

Firstly, if we use createEntry for the Customer entity; can we use createEntry to also create an address entity using the path of the not yet committed Customer entity (via navigation to the address)?

Secondly, if we enable batch mode in the Gateway model (define methods CHANGESET_BEGIN and CHANGESET_END); when we submitChanges, does this get updated as a single commit? e.g. If the address update fails; the customer creation is rolled back also?

Lastly, if we use a groupId against the above changes, can we do other updates independently of this? e.g. Imagine you need to create a new "City" entity in the database to be used for the address; but that must be committed independently of the Customer.

You would think the above would be really obvious, but nothing in my reading, or looking at many of the existing Fiori apps really cover this off effectively.



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

2 Answers

Ian MacGregor Nov 01, 2016 at 01:53 AM

Hi Matt,

Your first question is one I've struggled with and am looking forward to reading any responses. In the past I've ditched createEntry (of associated entities) for JSON models. It did seem possible by adding the generated path (minus the /) to the association array property of the principle entity, however for me this caused issues whenever bindings were automatically refreshed it would try and read entries for the generated (invalid) keys.

Regarding your second question, one way to ensure that related updates are processed together and committed at the correct time is to set CV_DEFER_MODE to true in CHANGESET_BEGIN and handle the updates together in CHANGESET_PROCESS. Alternatively, if CHANGESET_BEGIN is implemented to allow the updates of more than one entity without the CV_DEFER_MODE flag, processing will happen within individual entity CREATE/UPDATE/DELETE methods and (from memory) a commit work is only possible in the CHANGESET_END method, so you then need to determine in your CRUD methods whether it's a multi vs single entity update and process commits accordingly.

Anyway, hope this may help a little...interested to see other perspectives on the topic.



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

Thanks Ian - Definitely a piece of the puzzle and glad the answer to this can help others...Note - The reason for going this path is using createEntry and directly binding odata is by far the easiest way to handle things like draft handling and the like; albeit there are many more questions I have around error handling/checking etc when doing this, but that's another day...

Matt Harding
Nov 01, 2016 at 03:47 AM

Thanks to Leigh Mason (& thanks to Nigel James for putting him in touch with me), he pointed me at a response about Content Id Referencing from Andre Fischer which seems to be a big part of the answer to all this:

The help link to Content Id Referencing supported since Gateway SPS13:

Now if someone could pull a UI5 through to Gateway backend example of all this - I might know what to do! e.g. Not sure how UI5 leverages Content Id Referencing in the v2 Odata model yet...Seems kind of crazy that a very standard scenario does not any well defined examples I can follow out there...



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

About a year ago Kenichi Unnai posted an amazing blog about content id referencing: Introduction: OData $batch Processing with Content ID in SAP Gateway

Some time ago I wondered how to use UI5 File Upload via OData Batch Request to Keep Transaction Security? I still believe content id referencing would be the right way to go...

However, as I found out UI5 did not support and still does not support content id referencing (while SAP GW supports it for quite a while...). There is even an open feature request on github for that. I'd be happy to see more people voting for that feature...

Best, Nabi