[ https://issues.apache.org/jira/browse/OLINGO-574?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14323766#comment-14323766 ]
Chandan V.A commented on OLINGO-574: ------------------------------------ Hello [~xenevreu], As Michael mentioned currently there is no support for such a use case. However POST on Navigation property is supported. For example to create a new Sales Order for a Customer and to link both (in atom+xml format) you need to fire the below request. Please note for the Link tag which is used for linking Customer and Sales Order. Without this link tag, the linkage will not happen. {code:xml} POST /Customers(100L)/orders Content-Type: application/json <?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="http://localhost:9080/olingo-odata2-jpa-processor-ref-web/SalesOrderProcessing.svc/"> <link href="Customers(100L)" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/customer" title="customer" type="application/atom+xml;type=entry" /> <content type="application/xml"> <m:properties> <d:creationDate>2013-01-01T18:30:00</d:creationDate> <d:currencyCode>USD</d:currencyCode> <d:FK_customer>100</d:FK_customer> <d:deliveryStatus>01</d:deliveryStatus> <d:grossAmount>0.0</d:grossAmount> <d:longText m:null="true" /> <d:NetAmount>0.0</d:NetAmount> <d:shortText m:null="true" /> <d:ID>2000</d:ID> <d:status m:null="true" /> </m:properties> </content> </entry> {code:} JSON Payload {code:xml} { "d": { "__metadata": { "id": "http://localhost:9080/olingo-odata2-jpa-processor-ref-web/SalesOrderProcessing.svc/SalesOrders(2000L)", "uri": "http://localhost:9080/olingo-odata2-jpa-processor-ref-web/SalesOrderProcessing.svc/SalesOrders(2000L)", "type": "SalesOrderProcessing.SalesOrder" }, "creationDate": "\/Date(1357065000000)\/", "currencyCode": "USD", "FK_customer": "100", "FK_customer1": null, "deliveryStatus": "01", "grossAmount": "0.0", "longText": null, "NetAmount": "0.0", "shortText": null, "ID": "3000", "status": null, "customer": { "__metadata": { "uri": "Customers(100L)" } } } } {code} Finally as Michael mentioned try using Deep insert in this case as it supports both creation and linking. Regards Chandan > Batch request inserting master/detail entities not working > ---------------------------------------------------------- > > Key: OLINGO-574 > URL: https://issues.apache.org/jira/browse/OLINGO-574 > Project: Olingo > Issue Type: New Feature > Components: odata2-jpa > Affects Versions: V2 2.0.1 > Environment: JPA (Hibernate), MacOS, tomcat 7, Oracle 12c database > Reporter: Ivan Lucas Vargas > Assignee: Michael Bolz > > According to the OData specification, we can relate post requests for > inserting entities in the same batch request: > http://www.odata.org/documentation/odata-version-2-0/batch-processing (item > 2.2.1 - Referencing requests in a changeset) > Olingo should understand the master / detail relationship as per metadata > navigation properties and: > 1. Insert the master entity and get the sequence Id of it (as per JPA mapping) > 2. Before inserting the details entities, it should update this entities by > setting the master id into the details entities, and then persist to respect > the fk relationship > When sending the request, Olingo does not understand this relationship and > does not update the details entities with the Id of the master entity. > Details: > I'm trying to insert one entity with a list of another entity in the same > batch request. In my case, the post payload is: > --batch_98b2-5d17-73e4 > Content-Type: multipart/mixed; boundary=changeset_3d94-0d7a-375d > --changeset_3d94-0d7a-375d > Content-Type: application/http > Content-Transfer-Encoding: binary > POST Orders HTTP/1.1 > Content-ID: 1 > DataServiceVersion: 2.0 > Accept: application/atomsvc+xml;q=0.8, > application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1 > Content-Type: application/json > MaxDataServiceVersion: 3.0 > {"OrderId":-1,"Customer":1} > --changeset_3d94-0d7a-375d > Content-Type: application/http > Content-Transfer-Encoding: binary > POST OrderItems HTTP/1.1 > Content-ID: 2 > DataServiceVersion: 2.0 > Accept: application/atomsvc+xml;q=0.8, > application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1 > Content-Type: application/json > MaxDataServiceVersion: 3.0 > {"OrdemItemId":-2,"OrderId":-1,"ProductId":132} > --changeset_3d94-0d7a-375d-- > --batch_98b2-5d17-73e4-- > The idea here is to insert both entities. So, we have the OrderId: -1 and > OrderItemId: -2. This way, olingo will understand and generate the ids based > on the Oracle sequence mapped into the JPA entities. But, as far as I read > till now, the second changeset should reference the first changeset, by using > the $ in the POST. So, it should be: > POST OrderItems HTTP/1.1 (original) -> POST $1/OrderItems HTTP/1.1 (by > referencing the content-id: 1 of the first changeset) > Is this understanding correct? If yes, the second question is: My payload > needs to have the navigation link included? In this case, the payload sould > be something like: > {"OrdemItemId":-2,"OrderId":-1,"ProductId":132} (original) -> > {"OrdemItemId":-2,"OrderId":-1,"ProductId":132, OrderDetails: {url: > __deferred}} > Is this understand also correct? Or by the navigation link olingo will > understand that in the entity OrderItem, the property OrderId is a property > link and will resolve this referenced request and will fill the attribute > OrderItem.OrderId with the Order.OrderId that was already updated with the > sequence value got from the entity resolution of the first changeset? > The navigation property for this relationship generated by the $metadata is: > <NavigationProperty Name="OrderDetails" Relationship="pu.Order_OrderItem" > FromRole="OrderItem" ToRole="Order"/> -- This message was sent by Atlassian JIRA (v6.3.4#6332)