Hi guys,

I have a quick question. I am new to Neo4j and I am having some problems to 
figure out what is the retrieval order for collections in Neo4j. 

My example is pretty easy, I have a Person class which defines a Collection 
of Addresses as follow:

@Data
@NodeEntity
@AllArgsConstructor
@EqualsAndHashCode(of = "name")
public class Person {


    @GraphId
    private Long id;
    private String name;


    @Relationship(type = "LIVES_IN")
    private List<Address> addresses = new ArrayList<>();
} 

Address Class is simple as:

@Data
@NodeEntity
@AllArgsConstructor
@ToString(of = "name")
@EqualsAndHashCode(of = "name")
public class Address {


    @GraphId
    private Long id;
    private String name;
}

The problem i am facing is basically that the order of the address 
collections when I load a Person is not the same as the order I added the 
address into the collection.

Person p = new Person(null, "Person", new ArrayList());
Address a1 = new Address(null, "Address 1");
Address a2 = new Address(null, "Address 2");
Address a3 = new Address(null, "Address 3");


p.add(a1);
p.add(a2);
p.add(a3);


personRepository.save(p);


Person person = personRepository.findOne(p.getId());
person.getAddresses().stream().forEach(System.out::println);


The result I am getting after running this code is:

Address(name=Address 2)
Address(name=Address 1)
Address(name=Address 3)

Is there any way to preserve the insertion order?

The example can be found 
here: https://github.com/mmonti/neo4j-person-address

Thanks.
M.-

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to