java - Why does @RelatedToVia have optional type and elementClass parameters? -


@relatedtovia in spring-data-neo4j annotates field on nodeentity object reference @relationshipentity object connecting node node. @relatedto, in contrast, marks field reference connected node itself, , has optional type parameter can used specify type of relationship between 2 nodes.

@relationshipentity(type="some_link") class somelink {      @startnode      foonode foo;      @endnode      barnode bar; }  @nodeentity class foonode {     @relatedto(type="some_link")     barnode bar;      @relatedtovia(type="some_link") //what's point in annotation?      somelink link;  } 

@relatedtovia has same optional type parameter, , i'm curious why is: type of relationship specified in field type (a field annotated @relatedtovia must typed @relationshipentity-annotated class, must specify type compile), point of specifying in annotation parameter?

even more confusingly, @relatedtovia has optional elementclass parameter that, according docs, "returns target relationship entity class" - exactly what's specified in field type.

@relatedtovia(elementclass=somelink.class)  //what's point?  somelink link;   @relatedtovia(elementclass=someotherlink.class)  // ????  somelink link;  

i'm curious because have hunch intended enable useful polymorphic behavior relationshipentity classes , relatedtovia fields, , i'd love see example of how such behavior might implemented. bonus, different sorts of behaviors can achieved using 2 different annotations?

also, seems curious both these parameters exist (possibly redundantly) specifying type of relationship, while no parameter exists specifying class of node on other end of relationship - can isn't declared in relationshipentity class, , have been useful me on couple of occasions. why might be?

this:

@relatedtovia(type="some_link") 

has precedence over

@relationshipentity(type="some_link") 

and

@relatedtovia(elementclass=someotherlink.class)  // indeed redundant somelink link;  // not redundant, lose type information in runtime in java // know link set, don't know of type @relatedtovia(elementclass=someotherlink.class)       set<somelink> link; 

having multiple ways set relationship gives flexibility. can reuse same relationship class multiple different relationship types have same properties.

see more in reference docs

http://docs.spring.io/spring-data/data-neo4j/docs/3.1.4.release/reference/html/programming-model.html#reference_programming_model_relationships_relationshiptypeprecedence


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -