i have 1 question. using neo4j-ogm snapshot 1.5 . have following classes:
@nodeentity public abstract class entity { @graphid protected long id; @expose protected string code = null; @override public boolean equals(object o) { if (this == o) return true; if (o == null || id == null || getclass() != o.getclass()) return false; entity entity = (entity) o; if (!id.equals(entity.id)) return false; return true; } @override public int hashcode() { return (id == null) ? -1 : id.hashcode(); } public long getid(){ return id; } public void setid(long neo4jid){ this.id = neo4jid; } public string getcode(){ return code; } public void setcode(string code){ this.code = code; } } public class propertygroup extends entity{ @expose private string name; public propertygroup(){ } public string getname() { return name; } public void setname(string name) { this.name = name; } } public class user extends entity { private long registration_date; private long last_login_date; private boolean is_admin = false; private string push_dev; private string push_id; private boolean push_enabled = false; @expose private string avatar; @expose private string avatarurl; @expose private string name; @expose private volatile string password; @expose private int likes = 0; @expose private int questioncount = 0; @expose private int followerscount = 0; @expose private boolean isfollowing = false; // public set<userpropertyrelation> properties; // @relationship(type = modelreltype.answered) // public set<useransweredrelation> useranswers; // // @relationship(type = modelreltype.likes) // private set<likesquestionrelation> questionsliked; @expose @relationship(type = modelreltype.has_property) private set<propertygroup> properties; // private profile userprofile; // private list<fact> facts; // @expose // @relationship(type = modelreltype.owns) // private list<question> questions; public user(){ // this.properties = new linkedhashset<userpropertyrelation>(); // this.useranswers = new linkedhashset<useransweredrelation>(); // this.userproperties = new hashset<propertygroup>(); // this.setfacts(new arraylist<fact>()); this.properties = new hashset<propertygroup>(); } public user(long regdate, long lastlogindate, boolean isadmin, string pushdev, string pushid, boolean pushenabled){ this(); this.registration_date = regdate; this.last_login_date = lastlogindate; this.is_admin = isadmin; this.push_dev = pushdev; this.push_id = pushid; this.push_enabled = pushenabled; } // public void adduseransweredrelation(useransweredrelation answer){ // answer.setstartnode(this); // this.useranswers.add(answer); // } // // public set<useransweredrelation> getuseransweredrelations() { // return this.useranswers; // } // public void setuseransweredrelations(set<useransweredrelation> useranswers){ // for(useransweredrelation : useranswers){ // a.setstartnode(this); // } // // this.useranswers = useranswers; // } // // public void adduserpropertyrelation(userpropertyrelation rel){ // rel.setuser(this); // properties.add(rel); // } // // public void setuserpropertyrelations(set<userpropertyrelation> properties){ // for(userpropertyrelation r: properties){ // r.setuser(this); // } // // this.properties = properties; // } // public set<userpropertyrelation> getuserpropertyrelations(){ // return this.properties; // } public long getregistrationdate() { return registration_date; } public void setregistrationdate(long registrationdate) { this.registration_date = registrationdate; } public long getlastlogindate() { return last_login_date; } public void setlastlogindate(long lastlogindate) { this.last_login_date = lastlogindate; } public boolean isadmin() { return is_admin; } public void setadmin(boolean isadmin) { this.is_admin = isadmin; } public string getpushdev() { return push_dev; } public void setpushdev(string pushdev) { this.push_dev = pushdev; } public string getpushid() { return push_id; } public void setpushid(string pushid) { this.push_id = pushid; } public boolean ispushenabled() { return push_enabled; } public void setpushenabled(boolean pushenabled) { this.push_enabled = pushenabled; } public string getavatar() { return avatar; } public void setavatar(string avatar) { this.avatar = avatar; } public string getname() { return name; } public void setname(string name) { this.name = name; } public set<propertygroup> getproperties() { return properties; } public void setproperties(set<propertygroup> properties) { this.properties = properties; } // public profile getuserprofile() { // return userprofile; // } // // public void setuserprofile(profile userprofile) { // this.userprofile = userprofile; // } // public set<likesquestionrelation> getquestionsliked() { // return questionsliked; // } // // public void setquestionsliked(set<likesquestionrelation> likes) { // this.questionsliked = likes; // } public string getpassword() { return password; } public void setpassword(string password) { this.password = password; } // public list<fact> getfacts() { // return facts; // } // // public void setfacts(list<fact> facts) { // this.facts = facts; // } public string getavatarurl() { return avatarurl; } public void setavatarurl(string avatarurl) { this.avatarurl = avatarurl; } public int getlikes() { return likes; } public void setlikes(int likes) { this.likes = likes; } public int getquestioncount() { return questioncount; } public void setquestioncount(int questioncount) { this.questioncount = questioncount; } public int getfollowerscount() { return followerscount; } public void setfollowerscount(int followerscount) { this.followerscount = followerscount; } public boolean isfollowing() { return isfollowing; } public void setfollowing(boolean isfollowing) { this.isfollowing = isfollowing; } // public list<question> getquestions() { // return questions; // } // // public void setquestions(list<question> questions) { // this.questions = questions; // }
when trying following:
sessionfactory sessionfactory = new sessionfactory(modelspackagename); session session = sessionfactory.opensession(url); string cypher = "match (u:user {code: {code}})-[h:has_property]->(pg:propertygroup) " + "return u, h, pg"; map<string, object> params = new hashmap<string, object>(); params.put("code", "fc48b19ba6f8427a03d6e5990bcef99a28f55592b80fe38731cf805ed188cabf"); // system.out.println(util.mergeparamswithcypher(cypher, params)); user u = session.queryforobject(user.class, cypher, params);
the user object (u) never contains properties (propertygroup entity not mapped).
what doing wrong? appreciated.
regards,
alex
if you're using queryforobject
return 1 column- object, in case u
. neo4j ogm 1.x not support mapping of custom query results domain entities, have return entity id, , additional load-by-id specifying custom depth.
ogm 2.0 (currently 2.0.0-m01) support mapping custom query results entities. query remain same (i.e. return u,h,pg
) instead you'll use query()
method returns result
. result, you'll able user entity column-name u
, it'll hydrated propertygroups related to.
update: dependencies ogm 2.0.0-m01 are
<dependency> <groupid>org.neo4j</groupid> <artifactid>neo4j-ogm-api</artifactid> <version>2.0.0-m01</version> </dependency> <dependency> <groupid>org.neo4j</groupid> <artifactid>neo4j-ogm-core</artifactid> <version>2.0.0-m01</version> </dependency>
be sure read configuration changes since you're upgrading ogm 1.x http://neo4j.com/docs/ogm/java/2.0.0-m01/#reference_setup
a summary of new features: http://neo4j.com/blog/neo4j-ogm-2-0-milestone-1/
Comments
Post a Comment