当我在ArangoDb和Spring Data 集成中使用方法名查询时,我总是得到空列表。我使用方法的问题是什么?这是一个例子。
这些实体包括:
授权人:
@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;
}
}
用户授权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中存在所有文档和边,但结果为空。
1条答案
按热度按时间2mbi3lxu1#
查询派生会对文档字段生成AQL查询,例如,在
findAllByUser
的情况下,它会执行如下AQL查询:FOR a IN authorizations FILTER a.user == @user RETURN a
这显然会返回一个空数组。
您可以在logback.xml中检查生成的全局启用调试日志级别的查询。
根据您的数据模型,要获取给定用户的所有授权,您应该执行如下操作: