neo4j - The @QueryResult doesn't work -
i'm using spring data neo4j 4 (sdn4),and trying return more 1 entities using @queryresult
there no exception thrown,but null in @queryresult object model simple (:user)-[:role]-(:role)
does 1 know root cause?
the user model
@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; } }
the role model
@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); } }
the queryresult
@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); } }
the userrepository
public interface userrepository extends graphrepository<user>{ public user findbyuserid(string userid); @query(" match (u:user)-[:role]->(r) return u user , collect(r) roles ") public userpermission finduserwithroles(); }
and log
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 no existing transaction, creating transient 1 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 user , collect(r) roles","parameters":{},"resultdatacontents":["row"],"includestats":false}]} 2015-08-05 17:56:18 info defaultrequest:86 - response ok, creating response handler 2015-08-05 17:56:18 warn singleuseentitymapper:97 - unable find property: roles on class: model.userpermission writing 2015-08-05 17:56:18 warn singleuseentitymapper:97 - unable find property: user on class: model.userpermission writing 2015-08-05 17:56:18 info jsonresponse:103 - closing httpresponse
there's no support @ moment map entities @queryresult
. instead of returning user
, role
you'll have return user id's , role id's , hydrate them using load
example.
alternatively, if you're looking simple way find users roles, might try method such list<user> findbyrolesname(string rolename)
on userrepository
Comments
Post a Comment