Skip to content

Fix detection of common element types in collections of persistent entities. #2244

Closed
@jposthauer

Description

@jposthauer

Given the below setup, I get an error when I try to call the saveAll method to save multiple different subtypes of the same parent.

@Node
public abstract class Step {
    //some properties

    @Node
    public static class Chain extends Step {
        //some properties
    }

    @Node
    public static class End extends Step {
        //some properties
    }

    @Node
    public static class Origin extends Step {
        //some properties
    }
}

public interface StepRepository extends Neo4jRepository<Step, String> {

}

public class SomeService() {
    someMethod() {
        List<Step> steps = List.of(new Origin(), new Chain(), new End());
        stepRepository.saveAll(steps);
    }
}

Error details:
java.lang.IllegalArgumentException: Type must not be null!
In Neo4jTemplate - Class<T> domainClass = (Class<T>) CollectionUtils.findCommonElementType(entities); is returning null because CollectionUtils.findCommonElementType is counting the sub types as different class types.

Spring Boot: 2.4.5
Spring Data Neo4j: 6.0.8

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions