如何使用Spring Data ArangoDB在边缘重新获取附加属性

问题描述 投票:0回答:1

我刚刚开始用ArangoDB和它的spring数据库实现一个业余项目。

我已经创建了两个文档,名字分别为User和Post。并创建了一个名为Vote的边缘。

我在 Vote 上有一个不同于 _from 和 _to 的 custum 属性。我可以用该自定义属性保存该边缘,也可以从 ArangoDB ui 中看到它。但我无法用我的Java对象重新获取该属性。

我的环境;ArangoDB版本:3.6.3, arangodb-spring-data版本:3.1.0。

我的Clases在下面。

@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;
  }

}
spring-data arangodb
1个回答
1
投票

@Relations 注解应该应用于代表相关顶点的字段(不是边)。例如:这个应该可以。

  @Relations(edges = Vote.class, lazy = true, direction = Direction.INBOUND)
  Collection<User> usersWhoVoted;

这里是相关文档。https:/www.arangodb.comdocs3.6driversspring-data-reference-mapping-relations.html

© www.soinside.com 2019 - 2024. All rights reserved.