I just start implementing a hobby project with ArangoDB and its spring data library.
I have created two documents with names User and Post. And have created one edge with name Vote.
I have a custom attribute on Vote different then _from and _to. I can save that edge with that custom attribute and also can see it from ArangoDB ui. But I couldn't retrieve that attribute with my Java object.
My environment:
My classes are these:
@Document("posts")
@Getter @Setter @NoArgsConstructor
public class Post {
@Id
String id;
@Relations(edges = Vote.class, lazy = true, direction = Direction.INBOUND)
Collection<Vote> votes;
@Ref
User writtenBy;
String content;
List<String> externalLinks;
List<String> internalLinks;
public Post(String content) {
super();
this.content = content;
}
}
@Document("users")
@Getter @Setter @NoArgsConstructor
public class User {
@Id
String id;
String name;
String surname;
String nick;
String password;
public User(String name, String surname, String nick) {
super();
this.name = name;
this.surname = surname;
this.nick = nick;
}
}
@Edge
@Getter @Setter @NoArgsConstructor
@HashIndex(fields = { "user", "post" }, unique = true)
public class Vote {
@Id
String id;
@From
User user;
@To
Post post;
Boolean upvoted;
public Vote(User user, Post post, Boolean upvoted) {
super();
this.user = user;
this.post = post;
this.upvoted = upvoted;
}
}
The @Relations
annotation should be applied to a field representing the related vertexes (not edges). Eg. this should work:
@Relations(edges = Vote.class, lazy = true, direction = Direction.INBOUND)
Collection<User> usersWhoVoted;
Here is the related doc: https://docs.arangodb.com/3.11/develop/integrations/spring-data-arangodb/reference-version-4/mapping/relations/