I'm using Spring Data Neo4j 2.2.2 and I'm having trouble persisting multiple relationships with the same start and end node.
Assume a Person can have multiple Contracts with a Company. I modelled this as
@NodeEntity
public class Company {...}
and
@NodeEntity
public class Person {
@RelatedToVia
private Set<Contract> contracts;
...
}
and
@RelationshipEntity
public class Contract {
@StartNode
private Person person;
@EndNode
private Company company;
...
}
To add a contract to a person, I'm writing code like
Contract contract = new Contract();
contract.setPerson(person);
contract.setCompany(company);
// set other contract properties
person.getContracts().add(contract);
personDao.save(person)
where personDao
is a GraphRepository<Person>
.
In my tests, I can add a new Contract to a Person if that Person doesn't already have a Contract for the same Company. But if I try to add a new Contract to a Person with the same Company end node as an existing Contract it doesn't get saved.
equals()
and hashCode()
are implemented against @GraphId
, and I've confirmed that all objects are in the Contract Set
when I call save
. I've also tried with Collection
instead of Set
to no avail.
Any idea what could be wrong?