Error loading recursive relation loadAll using identifiers

Using the new OGM Neo4j 2.3. When I try to load objects 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 objects of Person, Alex, containing two friends (Guy, Joseph) and Nati, containing one friend, but what he actually returns is 5 objects (Alex, Guy, Joseph, Nati, Amit). Although Mike and Nati keep their friends inside, it seems strange (and, of course, undesirable) that I asked Faces with two identifiers and got an Iterable containing 5. Does anyone know why this is? this is mistake?

+5
source share
2 answers

This issue is now fixed in assembly 1.1.4-SNAPSHOT.

+1
source

This is by design. OGM has the concept of depth of search. By default (and in your example explicitly), the search depth is 1, which means selecting the requested objects from the graph along with their closest neighbors. You can set the search depth explicitly if you do not want this behavior. By setting it to zero:

 session.loadAll(Person.class, Arrays.toList(new Long() { 1L, 4L }), 0) 

will retrieve only the requested objects.

+1
source

Source: https://habr.com/ru/post/1235040/


All Articles