aGO
aGO

Reputation: 1363

Ordering a nested collection

We have an entity like this

@NodeEntity(label = "User")
public class UserEntity {
    @GraphId
    private Long mId;

    @Property(name = "address")
    private String address;

    @Relationship(type="FRIEND_WITH", direction = Relationship.INCOMING)
    private List<UserEntity> friends;

    @Relationship(type="OWNS")
    private List<CarEntity> cars;

and we would like to retrieve a list of User hydrated up to one level with the collections ordered by a property (creationDate).

We started with this but we don't know how to order the collections

MATCH p = (u:User) - [*0..1] - () WHERE <condition> RETURN nodes(p), relationships(p)

Upvotes: 0

Views: 145

Answers (1)

František Hartman
František Hartman

Reputation: 15086

Keeping order of results in mapped collections becomes ambiguous when your path has length > 2 and can have cycles.

If you want to impose order on collections of relationships you have several options:

  • use a -SortedSet- and implement Comparable in your entities
  • sort relationships in setter method

You can sort either by a property of a related node or by relationship property - for that you need a relationship entity.

Upvotes: 2

Related Questions