java - RelationshipEntity not persisted -


i'm having problems relation

@relationshipentity(type = reltypes.tag.tag_on_object_evaluation) public class tagonobjectevaluation {   @startnode   private mashup taggableobject;    @endnode   private tag tag;    // other fields, getters , setters } 

in both entities involved (mashup , tag), have field (with opposite direction)

@relatedtovia(type = reltypes.tag.tag_on_object_evaluation,       direction = direction.incoming /*direction.outgoing*/)   private set<tagonobjectevaluation> tagonobjectevaluations =       new hashset<tagonobjectevaluation>(); 

then, have various service class manage tag, mashup , tagonobjectevaluation. class under test latter. note: name bit confusing , it's legacy previous coder, can read dao service. genericneo4jdaoimpl (again, read genericserviceneo4jimpl) defines standard methods entities management (create(), find(), update(), delete(), fetch() )

@service public class tagonobjectevaluationdaoneo4jimpl extends     genericneo4jdaoimpl<tagonobjectevaluation> implements     tagonobjectevaluationdao {   @autowired   private tagonobjectevaluationrepository repository;    public tagonobjectevaluationdaoneo4jimpl()   {     super(tagonobjectevaluation.class);   }    public tagonobjectevaluationdaoneo4jimpl(       class<? extends tagonobjectevaluation> entityclass)   {     super(entityclass);   }    @override   public tagonobjectevaluation create(tagonobjectevaluation t)   {     transaction tx = template.getgraphdatabaseservice().begintx();     tagonobjectevaluation savedt = null;     try     {       // enforce uniqueness of relationship. know can fail in many ways, not problem atm        savedt =           template.getrelationshipbetween(               t.gettaggableobject(), t.gettag(),               tagonobjectevaluation.class,               reltypes.tag.tag_on_object_evaluation);       if (savedt == null)         savedt = super.create(t);       tx.success();     }     catch (exception e)     {       tx.failure();       savedt = null;     }         {       tx.finish();     }     return savedt;   } } 

it seems pretty straightforward until now. when i'm trying persist relationshipentity instance, have many problems.

  @test   public void testrelationshipentitywaspersisted()   {     tagonobjectevaluation tagonobjectevaluation = new tagonobjectevaluation(taggedobject, tag);      tagonobjectevaluationdao.create(tagonobjectevaluation);     assertnotnull(tagonobjectevaluation.getid());     logger.info("tagonobjectevaluation id = " + tagonobjectevaluation.getid());      tagdao.fetch(tag);     assertequals(1, tag.gettaggedobjectsevaluations().size());   } 

the last test fail: size 0 , not 1. also, although seems entity correctly stored (it gets id assigned), if i'm navigating db later on there no track of @ all. i've tried add relationship in different way, using sets of involved nodes; f.e.

tag.gettaggedobjectsevaluations().add(tagonobjectevaluation); tagdao.update(tag);  

but no improvements @ all.

you need change direction of relationship in entity mashape, (entity corresponding @startnode of @relationshipentity tagonobjectevaluation).

@nodeentity class mashape {     // ...    @relatedtovia(type = reltypes.tag.tag_on_object_evaluation, direction = direction.outgoing)    private set<tagonobjectevaluation> tagonobjectevaluations = new hashset<tagonobjectevaluation>();      } 

just point according specifications of @relatedtovia spring-data-neo4j annotation, direction default outgoing, don't need specify direction in case. should correct:

   @relatedtovia(type = reltypes.tag.tag_on_object_evaluation)    private set<tagonobjectevaluation> tagonobjectevaluations = new hashset<tagonobjectevaluation>();     

hope helps.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -