2

I have a Spring Boot application using Spring Data Neo4j 4 (4.0.0.RELEASE and Neo4j Community Server 2.2.5). I'm using the latest snapshot version of the neo4j-ogm library (1.1.4-SNAPSHOT) as the dependency for SDN 4. The application and now an integration test do not behave as I was expecting when there are multiple relationships (not using relationship entities) differentiated by relationship type between the same two node entity classes.

The two node entity classes for the failing integration test are:

@NodeEntity
public class TypeD {

    @GraphId
    private Long id;

    @Relationship(type = "ONE", direction = Relationship.OUTGOING)
    private TypeE one;

    @Relationship(type = "MANY", direction = Relationship.OUTGOING)
    private Set<TypeE> many;

    private String identifier;
    ...


@NodeEntity
public class TypeE {

    @GraphId
    private Long id;

    @Relationship(type = "ONE", direction = Relationship.INCOMING)
    private Set<TypeD> firstColl;

    @Relationship(type = "MANY", direction = Relationship.INCOMING)
    private Set<TypeD> secondColl;
    ...

The integration test starts with two nodes with an existing ONE relationship already in the datastore

starting datastore content

    // Find the TypeE node using its String identifier
    TypeE e = typeERepository.findByIdentifier(EEE);
    assertNotNull(e);
    assertEquals(EEE, e.getIdentifier());

    // Create a new TypeD object
    TypeD d = new TypeD();
    // and create a relationship between d and the TypeE node
    d.setOne(e);
    d.setIdentifier(TWO);
    // note that the e object is NOT added to the many collection 
    // and save d
    TypeD savedD = typeDRepository.save(d);

I would have expected the outcome to be

expected datastore content

but it's actually

actual datastore content

So unexpectedly - at least to me - a new relationship is created between the nodes that existed before the new object was created and saved.

When starting with multiple (EEE)<-[:ONE]-(d) relationships already in the datastore each (d) gets a new [:MANY] relationship to (EEE) when a new TypeD object is created and saved.

One of the real application scenarios for this is User ownership and licensing relationships to other Items. So TypeE would be a User and TypeD is an owned or licensed Item. A User can own or license multiple Items of the same type. An Item can only have one owner BUT it can be licensed to multiple Users. The relationships in the test would therefore be ONE = owner and MANY = licensee.

Is there a mistake here or anyone seen anything similar?

Luanne
  • 19,145
  • 1
  • 39
  • 51
GT2015
  • 85
  • 4
  • 1
    Possibly related issue: https://github.com/neo4j/neo4j-ogm/issues/38 Please could you confirm behaviour if the objects are fully connected on both sides, e.g ```d.setOne(e) e.setOne(d) ``` – Vince Oct 30 '15 at 02:38
  • @Vince thank you for that. I've just updated my test as you suggested and this time I do not see the extra MANY (in the code in the question) relationship created. So if the ONE relationship is symmetrical i.e. a single d is related to a single e and vice versa a single e is related to a single d through the same relationship type then the additional relationship(s) are not created. – GT2015 Oct 30 '15 at 11:22
  • @Vince the issue you highlight has relationships between entity classes that are in an inheritance hierarchy. I have seen a problem in this area in my application but I've not been able to pin it down yet in terms of a simple (integration) test. So not sure whether it's exactly the same problem as this one related to relationship symmetry and cardinality or something to do with node entity class hierarchies. – GT2015 Oct 30 '15 at 11:30

0 Answers0