Spring ArangoDb 的数据集成返回空的查询结果列表

Spring Data integration for ArangoDb gives back empty result list on queries

当我使用来自 ArangoDb 和 Spring 数据集成的方法名称的查询时,我总是得到空列表。 我使用的方式有什么问题? 这是一个例子。

这些是实体:

授权:

@Document("authorizations")
@Data // (Lombok)
public class Authorization {

  @Id
  private String id;

  private String caption;

  @Relations(edges = com.picktur.server.relations.UserAuthorized.class, lazy = true)
  private User user;

}

用户:

@Document("users")
@Data @NoArgsConstructor // (Lombok)
public class User {

  @Id
  private String id;

  private String username;

  @Relations(edges = com.picktur.server.relations.UserAuthorized.class, lazy = true)
  private Collection<Authorization> authorizations;

}

授权存储库:

public interface AuthorizationRepo extends ArangoRepository<Authorization, String> {

  Iterable<Authorization> findAllByUser(User user);

}

用户和授权之间的边界:

@Edge
@Data
public class UserAuthorized {

  @Id
  private String id;

  @From
  private User user;

  @To
  private Authorization authorization;

public UserAuthorized( User user, Authorization authorization) {
    this.authorizedPhoto = user;
    this.authorization = authorization;
}

}

UserAuthorized Egde 的存储库:

public interface UserAuthorizedRepo extends ArangoRepository<UserAuthorized, String> {

}

数据持久化逻辑:

    User user = get_user_from_security_context();
    Authorization authorization = new Authorization();        
    authorization.setUser(user);
    ...
    authorization = authorizationRepo.save(authorization);

    UserAuthorized userAuthorized = new UserAuthorized(user, authorization);
    userAuthorizedRepo.save(userAuthorized);

结果为空的查询:

Iterable<Authorization> authorizations = authorizationRepo.findAllByUser(user);

DB中所有文档和边都存在,但结果为空。

查询派生在文档字段上生成 AQL 查询,例如。在 findAllByUser 的情况下,它执行如下 AQL 查询:

FOR a IN authorizations FILTER a.user == @user RETURN a

这显然是 returns 一个空数组。

您可以在 logback.xml.

中全局检查生成的启用调试日志级别的查询

根据您的数据模型,要获取给定用户的所有授权,您应该执行如下操作:

User user = userRepo.findById(userId).get();
Iterable<Authorization> authorizations = user.getAuthorizations();