Skip to content

Object mapping does not work correctly with abstract superclass and recursion #2138

Closed
@rolevinks

Description

@rolevinks

Hi, I'm using the version 6.0.3 of Spring Data Neo4j and I have a problem with retrieving a simple data structure with an abstract superclass and recursion. The problem is, that the objects are not mapped to their correct type.

This is the model:

@Node("Entity")
public abstract class Entity {
    @Id
    @GeneratedValue
    private Long id;

    @Relationship(type = "IS_CHILD")    
    private Entity parent;
}

@Node("Company")
public class Company extends Entity {

    private String name;   
}

@Node("Site")
public class Site extends Entity {

    private String name;   
}

@Node("Building")
public class Buildingextends Entity {

    private String name;   
}

// omitted getters and setters for brevity

The data structure I've created is

Building -IS_CHILD-> Site -IS_CHILD-> Company

I have defined a BuildingRepository:

@Repository
public interface BuildingRepository extends Neo4jRepository<Building, Long> {
}

When I retrieve the building with the findById, the building is retrieved correctly. However, its parent is incorrectly mapped as a building, and the parent of this is incorrectly mapped as a site (in all cases the name-field is mapped correctly).

Expected Behavior:
I expect buildingRepository.findById() to return the building with its correctly mapped parent, and their correctly mapped parent etc.

Actual Behavior:
The parent of the building and the parent of this parent are not mapped to the correct type. I think it has something to do with the labels; when instantiating the parent, the labels of the sourcenode are being used to derive the concrete node description for the parent.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions