Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jposthauer opened this issue Apr 29, 2021 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@jposthauer
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 29, 2021
@michael-simons michael-simons self-assigned this Apr 30, 2021
@michael-simons michael-simons changed the title Unable to use saveAll to save multiple subtypes Fix detection of common element types in collections of persistent entities. Apr 30, 2021
@michael-simons michael-simons added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 30, 2021
@michael-simons michael-simons added this to the 6.0.9 (2020.0.9) milestone Apr 30, 2021
michael-simons added a commit that referenced this issue Apr 30, 2021
@michael-simons
Copy link
Collaborator

Nice catch, thank you for the detailed report.

michael-simons added a commit that referenced this issue Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants