In my project I use object of type A which has OneToMany relation (orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER) to objects of type B. I need SpringDataRest (SDR) to store complete full A object with its B objects (children) using single one POST request. I tried several combinations in SDR, the only one which worked for me, was to create @RepositoryRestResource for object A and to create @RepositoryRestResource also for object B, but mark this (B) as exported=false (if I did not create repository out of object B at all, it would not work -> just A object would be stored on single POST request, but not its children (@OneToMany relation) of type B; the same outcome occurs if exported=false is omitted for B repository). Is this ok and the only way how to achieve it (single POST request with storing all objects at once)?
The reason I'm asking, in my previous example, I have to (I would like to) control all objects "lifecycle" by using A's repository. I am ok with it, because A->B relation is composition (B does not exists outside of A). But I have serious problem of editing (also removing) one certain object of type B by SDR using its parent repository (since object B doest not have its own repository exported). Maybe, this is not possible by definition. I have tried these solutions:
- PATCH for "/A/1/B/2" does not work -> method not allowed (in headers is "Allow: GET, DELETE") -> so, also PUT is out of question
- Json Patch would not work either - PATCH for "/A/1" using json patch content-type [{"op": "add", "path": "/B/2", ....}] -> "no such index in target array" - because Json Patch uses scalar "2" after "array" as a index to its array. This is not practical in Java world, when relations are kept in Set of objects - indexing has no meaning at all.
- I could export repository (exported=true) of object B for manipulating it "directly", but this way I would loose ability to store the whole object A with its B objects at one single POST request as I have mentioned before.
I would like to avoid sending the whole A object with one single tiny modification of its B object for PUT, if possible. Thank you.