-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Relationship (type = "...") ArrayList<T> does not maintain list sequence. #386
Comments
Hi, Thanks for filing this issue. The OGM doesn't make any guarantees about ordering of results, unless you explicitly order them using a custom query. There are a couple of reasons for this: First, for performance reasons the OGM splits up insertion of nodes and edges when persisting your objects. The order in which edges are created is currently undefined. However, even if it did preserve the insertion order of edges this ordering would not be maintained when the data was read back again. This is because the OGM currently sends a generic query for any object to depth
Neo4j does not guarantee that these paths will be returned in any particular order, so the OGM is unable to preserve any initial ordering. |
@JAFriedrich for options how to achieve ordering on relationship please see https://neo4j.com/docs/ogm-manual/preview/reference/#_ordering This is being asked quite a lot. Maybe we should consider providing a way to do this automatically - storing internal order property and sorting by that. |
Hi, thank you for your quick and detailed responses. I'm really looking forward to have this available as native OGM feature. |
Would be very helpful for us too |
We could definitely make use of this feature |
If we would add an additional (transparent) sorting property to each relationship saved in an ordered collection, this should work. The sorting will then be programmatically done after loading the results from Neo4j. |
Status update: This brought more problems with it than expected especially in handling non-rich Relationships (not annotated with |
We don't have any means to make sure that relationships are retrieved in the same order as the database has written them without the user adding an additional ordering. At the moment, we're not adding a new order attribute to the relationship definition. As a workaround, make your relationship entity Thanks for your understanding. |
Expected Behavior
A Node A has a collection of type ArrayList as a relation e.g.:
1.) Add items to that ArrayList in a specific sequence.
2.) Persist Node A including it's direct neighbours (depth >= 1).
All ListItems are thus persisted and related to Node A.
3.) Restart application.
4.) Load Node A including neighbours (depth >=1).
Node A's ArrayList maintains it's original sequence.
Current Behavior
The ArrayList does not maintain it's original sequence.
The sequence of the ListItems in Node A's ArrayList is now random. Working with a list across multiple sessions is therefore not possible, if the list sequence is of interest - which is presumably typically the case.
Context
Native population of neighbours using the OGM Relationship mechanics would be far more convenient to use (if it was working as expected/described) than for example adding a relationship specific property and manually sorting after loading the collection of neighbours.
Edit:
This is different from #196, where there is not necessarily a relationship between the nodes and no annotated collection used. The collection mentioned is just a container on the client side.
Your Environment
The text was updated successfully, but these errors were encountered: