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
// 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
but it's actually
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?