I'm using Spring Data Neo4j 4.0.0 with Neo4j 2.2.1 and I'm trying to create a relationship between two nodes with the exact same labels.
So, I have a NodeEntity class and I have a variable inside with the same Type as the class itself, and annotate it as Relationship. But, when I save the object to the database using the save() method of the repository object, the relationship can't be created.
Thank you in advance and your suggestion would be really appreciated!
EDIT
Here is the node entity classes
public class ArchitectureUnitState extends UnitState {
public ArchitectureUnitState()
{
super();
}
public ArchitectureUnitState(String name, String description, String parentArchitectureUnitName)
{
super(name, description);
this.parentArchitectureUnitName = parentArchitectureUnitName;
}
@Relationship(type="PART_OF", direction = Relationship.OUTGOING)
private ArchitectureUnitState architectureUnitState;
@Relationship(type="STATE_OF", direction = Relationship.OUTGOING)
private ArchitectureUnit architectureUnit;
@Transient
private String parentArchitectureUnitName;
public void partOf(ArchitectureUnitState architectureUnitState) {
this.architectureUnitState = architectureUnitState;
}
public void stateOf(ArchitectureUnit architectureUnit) {
this.architectureUnit = architectureUnit;
}
public void childOf(String parentArchitectureUnitName) {
this.parentArchitectureUnitName = parentArchitectureUnitName;
}
public String getParentName() {
return parentArchitectureUnitName;
}
}
@NodeEntity
public class UnitState {
@GraphId
protected Long id;
private String name;
private String description;
public UnitState() {
}
public UnitState(String name, String description) {
this.name = name;
this.description = description;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
}
So, the sequence is: I created the ArchitectureUnitState objects, map one to another, then save with the save() method of the ArchitectureUnitStateRepository.
If I do like this, the PART_OF relationships aren't created, although I see in the debugging that the values are there.
My workaround right now is I save all the ArchitectureUnitState nodes first, retrieve them again from the database, map one to another, then save it again. This way, the relationships can be created, but I need to save two times.