Reputation: 15795
Using the new Neo4j 2.3 OGM. When trying to load entities by id I have the following problem:
@NodeEntity
class Person {
Long id;
String name;
@Relationship(type="Friend", direction = Direction.OUTGOING)
public List<Person> friends;
}
assuming (1, "Alex") is friends with (2, "Joseph") and (3, "Guy"). (4, "Nati") is friends with (5, "Amit"), using the following code:
session.loadAll(Person.class, Arrays.toList(new Long() { 1L, 4L }), 1)
should return 2 Person objects, Alex containing two friends (Guy, Joseph) and Nati containing one friend yet what it actually returns is 5 objects (Alex, Guy, Joseph, Nati, Amit). Although Mike and Nati do contain their friends within, it seems weird (and certainly unwanted) that I requested Persons by two ids and got an Iterable containing 5. Does anyone know why this is? is this a bug?
Upvotes: 5
Views: 153
Reputation: 2181
This is by design. The OGM has a concept of search depth. By default (and in your example, explicitly) the search depth is 1, meaning fetch the requested objects from the graph along with their immediate neighbours. You can set the search depth explicitly if you don't want this behaviour. Setting it to zero like this:
session.loadAll(Person.class, Arrays.toList(new Long() { 1L, 4L }), 0)
will fetch just the requested objects.
Upvotes: 1