Thursday, 15 May 2014

Neo4J Nodes and Relationships : Do I have to model everything as a Node? -



Neo4J Nodes and Relationships : Do I have to model everything as a Node? -

i trying utilize neo4j spring data, not sure if design right (first time utilize graph database). problem don't know if should model node or simple attribute.

example : (my biggest node)

@nodeentity public class user{ @indexed(unique=true) private string username; @indexed(unique=true) private string email; // node ??? private location location private int arearadius; //no need create rich relationship @relatedto(type=relationshiptypes.likes, direction=direction.outgoing) @fetch private set<hobby> hobbies = new hashset<hobby>; //no need create rich relationship @relatedto(type=relationshiptypes.has_category, direction=direction.outgoing, elementclass=category.class) @fetch private set<category> favcategories = new hashset<category>; //must create rich relationship (friendship.java) @relatedto(type=relationshiptypes.friend_of, direction=direction.both) @fetch private set<user> friends = new hashset<user>; //rich relationship between users (friendship.java) @relatedtovia(type=relationshiptypes.friend_of) @fetch private set<friendship> friendships = new hashset<friendship>; //must create rich relationship (userevent.java) @relatedto(type=relationshiptypes.going_to, direction=direction.outgoing) @fetch private set<event> events = new hashset<event>; //rich relationship between users (userevent.java) @relatedtovia(type=relationshiptypes.going_to) @fetch private set<userevent> userevents = new hashset<userevent>; // node ??? private set<status> statuslist; private uri profilepicture; public user(){} public user(string username, string email, location location){ this.username = username; this.email = email; this.location = location; } public void addhobby(hobby hobby){ this.hobbies.add(hobby); } public void sendfriendrequestto(user user){ this.friendships.add(new friendship(this, user, friendship.requested); } public void addcategory(category category){ this.favcategories.add(category); } public void addconfirmedevent(event event){ this.userevents.add(new userevent(this, event, false)); } public void addmaybeevent(event event){ this.userevents.add(new userevent(this, event, true); } }

my questions :

1) have model status , location nodes ?

status have : string text, set<string> tags, date date location have : country, city, postalcode, double[] coordinates.

2) don't understand how store related nodes spring info :

do need store relationships @relatedtovia or need store related nodes @relatedto or need store both

3) when add together liked movie, how have :

add in likedmovies set ? (the relationship automatically created ?) add in relationship set (ratings example) ? (then likedmovies set automatically updated in next fetch) add in both ?

4) friends set , friendships set, have specify same type (type = ) ?

edit :

new question :

5) if have same relationships different @startnodes (user has categories, film have category). have create 2 @relationshipentity different @startnode ? (it not rich relationship in case).

you should model entity, venue location field. location makes sense if connect more it.

it depends on model, if have rich relationships, can utilize @relatedtovia don't have to. see entities rather projections of use-cases, not "one size fits all" bite in end.

if have rich relationships should add together them @relatedtovia set. faster approach can utilize template.createrelationshipbetween(). or create relationshipentity, assign start end end-node , properties , save template.save().

yes, same relationship-type in annotation

do have "rich" relationship category? if not don't have model it. if yes, like? perhaps different types of category relationships create sense (also different rel-types)

it depends on model , use-cases remove @fetch annotations wherever possible load lot of data, might not need. utilize template.fetch(user.field) if needed.

for many use-cases recommend not loading , hydrating total entities database instead running query , projecting minimum amount of info returned list of view objects/dto's (annotated or derived) repository methods , @queryresult on pojo

neo4j relationship nodes spring-data-neo4j

No comments:

Post a Comment