【发布时间】:2020-02-03 14:29:22
【问题描述】:
当我通过 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;
}
}
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);
所有文档和边都存在于数据库中,但结果为空。
【问题讨论】:
标签: spring-boot spring-data-jpa spring-data graph-databases arangodb