-
Notifications
You must be signed in to change notification settings - Fork 693
DatastoreTemplate or Repository does not fetch SubChild Descendants (Multiple parent keys not supported) #2503
Comments
@sanveer-osahan Recursive save and retrieval works automatically for It is expected that fields of type Please reopen if you have further questions. |
@dmitry-s My requirement is to store and retrieve child objects based on their parent, and subchild objects based on their parent and child. I have to organize my data in the following manner (sequential ids):
Even if I use autogenerated keys, I will have to store sequential ids separately and for child and subchild, this will be an overhead because the parent field is used in datastore to track their ancestors and I am not able to take advantage of this functionality. |
@sanveer-osahan I'm not sure I understand what exactly you are trying to achieve. Do you need your child entities to be ordered? In that case, would embedded list work for you? Also, could you describe your use case in more details? It is not clear at this point why you need to store the sequential ids. Thanks! |
@dmitry-s I'm developing the following rest services:
I have to use datastore for performing CRUD operations(Update and Delete are not a priority as of now).
|
Update: The current workaround which I have mentioned is not working for spring cloud version Greenwich but working for Hoxton. |
@sanveer-osahan ok, I think I understand: you want to retrieve the descendants in order. This feature is not currently supported, but what we can do is to add an You would have to introduce a new field in the child entity class that would be used for sorting (which is a good thing - generally, it is not recommended to use keys for sorting because if you need to change ordering you would have to change keys). So your code would look something like this:
Would that work for you? Also, have you tried using embedded lists? They are stored and retrieved in order. Would that work for your case or is there some functionality that you can only achieve with using descendants? |
@dmitry-s This will address one of the issues that I'm facing. The other issue is about performing CRUD operations. |
I have a Parent/Child/SubChild relationship modeled as follows using
@Descendants
When you try to retrieve the parent object(s) using a DatastoreTemplate or Repository, they contain the child records but the child records do not contain subchild records.
Even if you try to recieve only the child object(s), they do not retrieve their subchild records.
Steps to Reproduce
I have created the following JUnit test to explain the issue:
Expected Result
The assertion should pass as we are trying to fetch the same entity object which was saved.
Actual Result
The assertion fails as the fetched entity doesn't retrieve the subchild record(s).
Additional Steps
Current Workaround
For now, I'm using the following alternative:
Parent(id=1, children=[Child(id=Key{projectId=costoptimizationproject, namespace=test, path=[PathElement{kind=parent, id=1, name=null}, PathElement{kind=child, id=null, name=1#2}]}, subChildren=[SubChild(id=Key{projectId=costoptimizationproject, namespace=test, path=[PathElement{kind=child, id=null, name=1#2}, PathElement{kind=subchild, id=3, name=null}]}, someValue=someValue)])])
This solution fetches the children along with their subchildren because now subchild entity has only single parent key. But I'm compelled to use parentId#childId as combination for child entity id.
Can there be a support for retrieving sub-descendants with multiple parent keys?
The text was updated successfully, but these errors were encountered: