我正在使用 Spring Data Neo4j 4 (SDN4),并尝试使用 @QueryResult 返回多个实体
没有抛出异常,但是@QueryResult 对象中的一切都是空的 模型很简单为 (:User)-[:ROLE]-(:Role)
有谁知道根本原因是什么?
用户模型
@NodeEntity
public class User implements UserDetails {
@GraphId
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private String userId;
@Relationship(type="ROLE")
private Set<Role> roles = new HashSet<>();
public ADUser getaDUser() {
return aDUser;
}
public void setaDUser(ADUser aDUser) {
this.aDUser = aDUser;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
榜样
@NodeEntity
public class Role implements java.io.Serializable {
@GraphId Long id;
private String name;
public Role(){}
public Role(String name){
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
}
查询结果
@QueryResult
public class UserPermission {
private User user;
private List<Role> roles;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List<Role> getRoles() {
return roles;
}
public void setRoles(List<Role> roles) {
this.roles = roles;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
}
用户存储库
public interface UserRepository extends GraphRepository<User>{
public User findByUserId(String userId);
@Query(" Match (u:User)-[:ROLE]->(r) return u as user , collect(r) as roles ")
public UserPermission findUserWithRoles();
}
日志是
2015-08-05 17:56:18 INFO Neo4jSession:461 - --------- new request ----------
2015-08-05 17:56:18 INFO Neo4jSession:461 - getOrCreateTransaction() being called on thread: 1
2015-08-05 17:56:18 INFO Neo4jSession:461 - Session identity: org.neo4j.ogm.session.delegates.TransactionsDelegate@1dcfae07
2015-08-05 17:56:18 INFO Neo4jSession:461 - There is no existing transaction, creating a transient one
2015-08-05 17:56:18 INFO DefaultRequest:57 - POST http://localhost:7474/db/data/transaction/commit, request: {"statements":[{"statement":"Match (u:User)-[:ROLE]->(r) return u as user , collect(r) as roles","parameters":{},"resultDataContents":["row"],"includeStats":false}]}
2015-08-05 17:56:18 INFO DefaultRequest:86 - Response is OK, creating response handler
2015-08-05 17:56:18 WARN SingleUseEntityMapper:97 - Unable to find property: roles on class: model.UserPermission for writing
2015-08-05 17:56:18 WARN SingleUseEntityMapper:97 - Unable to find property: user on class: model.UserPermission for writing
2015-08-05 17:56:18 INFO JsonResponse:103 - Closing HttpResponse