SDN 6 unable to create parent-child relationship if node extends a class

I'm new in this, but I have read tutorial before doing this.

I have a node:

@Node
@Data
@EqualsAndHashCode(exclude= {"parent", "roleList"})
public class Department extends AbstractEntity implements BaseEntity{
	
	@JsonIgnore
	@Relationship(type = "PARENT", direction = Relationship.Direction.INCOMING)
	private Department parent;
	
	@Relationship(type = "HAS", direction = Relationship.Direction.OUTGOING)
	private List<Role> roleList = new ArrayList<>();
	
}

It extends from AbstractEntity:

@data
public abstract class AbstractEntity {
	@Id
	private long id;
	private long companyId;
	private String name;
}

When I create parent relationship, it does not link two node, it points to itself.

	var parent = getById(parentId);
	var child = getById(childId);
	if (parent != null && child != null) {
		child.setParent(parent);
		return save(child);
	}

A child node becomes parent of itself (c)-[PARENT]->(c), nothing relates to parent node. I have debugged, parent and child are different nodes, no way they are the same. The save method just calls repository.save() method (extends Neo4JRepository). Other relationships work perfectly.

But if the Node doesn't inherit from AbstractEntity, the relationship points parent and child correctly (p)-[PARENT]->(c).

Is there anyone facing this? Or did I miss something?

I'm using spring 2.6.6 and it uses SDN 6.2.3, JDK 11.

org.springframework.boot:spring-boot-starter-data-neo4j:2.6.6

Testing on Neo4J community 4.8.8.

Thanks for your help.

I created a reproducer for your problem: https://github.com/meistermeier/neo4j-issues-examples/tree/master/community-57088


@NamTA wrote:

I have debugged, parent and child are different nodes, no way they are the same.


The underlying problem is that Lombok generates equals and hashCode just for this very class.
And as a result both are "the same".

Adding _callSuper_ will help:

@EqualsAndHashCode(exclude= {"parent", "roleList"}, callSuper = true)

I have found it when comparing two objects of Department, then I have added callSuper = true. I didn't notice it fixed this problem too. Thank you!