spring-data: Problems with @To and @From annotation

do the To and From annotations work in the spring data project?

when I try to retrieve edge documents using the From attribute, I get “nested exception is java.lang.StackOverflowError”. I can see the docs and the edge in the database. but when I use the repository (actorRepository.findByName), i get the above error. When I remove the From annotation, I don’t get that error

@Edge(value = "roles")
public class Role{
    @Id
    private String id;

    @From
    private Actor actor;

    @To
    private Movie movie;
}

@Document
public class Movie movie{
    @Id
    private String id;

    ...other stuff...
}

@Document
public class Actor actor{
    @Id
    private String id;
     
    private String name;


    ...other stuff...

    @From
    private List<Role> roles;

}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 34 (21 by maintainers)

Commits related to this issue

Most upvoted comments

I just released version 1.1.5 and 2.1.6 which contains a fix for this bug.

Thanks for explaining how this works. That’s what I meant by populated.

They are annotated with @Relations(..., lazy=true) and if I do nothing to trigger the lazy loading - like actor.getMovies.size() - they are still returned as populated.

By “populated” you mean serialized by Jackson to JSON? Keep in mind that Jackson triggers the resolution of the lazy loading class with its serialization process (by accessing it).

actor.setMovies(null);
return actor;

and so limiting the data being returned to the client, but am I then limiting the data being transferred from the database and reducing querying overhead?

If you don’t access movies before you set them to null, they are not loaded from the DB. So yes, you can reduce querying effort with this approach.

Sets will be supported with the next release.

@bthj-tms I think I’ve fixed this issue with PR #57.

@mpv1989 can you please have a look at PR #57?