Skip to content

Relation mapping using the most abstract label #2459

Closed

Description

@marichka-spin

Hello again team :)
I continue working over migrating our code to the new Spring Data. And currently I'm testing version 6.2.1-SNAPSHOT. Lets consider the case:

@Node("PetOwner")
public abstract class PetOwner {
    @Relationship(type = "hasPet")
    private List<Animal> pets;
}

@Node("Boy")
public class Boy extends PetOwner {}

@Node("Girl")
public class Girl extends PetOwner {}

@Node("Animal")
public abstract class Animal {}

@Node("Dog")
public class Dog extends Animal {}

@Node("Cat")
public class Cat extends Animal {}

So lets consider that Neo4j DB has Node(Boy) that has 1 relation to 1 Cat and 1 relation to 1 Dog, I assumed that projection view that looks like below should work and should result List pets with size 2 but results with NULL:
RETURN petOwner1{.*, PetOwner_hasPet_Animal | [....]}
But what I observed in DefaultNeo4jEntityConverter class (lines 349-354) relation mapping is executed in two phases using abstract source label and using concrete source label. During first phase PetOwner_hasPet_Animal is mapped well but during next phase mapped values are overwritten with empty ArrayList. MapAccessor values (line 542) doesn't contain key "Boy_hasPet_Animal" and empty collection is instantiated (line 658).
https://github.com/spring-projects/spring-data-neo4j/blob/6.2.x/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java

Thank you for the assistance!

Activity

  1. self-assigned this
    on Dec 16, 2021
  2. marichka-spin commented on Dec 16, 2021

    @marichka-spin
    Author

    I've created test project to reproduce the issue https://github.com/idun-corp/neo4j-test
    Everything works using only embedded Neo4jDB

  3. meistermeier commented on Dec 22, 2021

    @meistermeier
    Collaborator

    Thanks for spotting this. I thought that I did something to avoid the override. Must have been wrong ;)

  4. marichka-spin commented on Dec 22, 2021

    @marichka-spin
    Author

    No problem! Looking forward to the fix! Wish you Merry Christmas and happy holidays

  5. added 2 commits that reference this issue on Dec 22, 2021
  6. meistermeier commented on Dec 22, 2021

    @meistermeier
    Collaborator

    There will be a little early Christmas present available for you with version 6.2.1-GH-2459-SNAPSHOT. 🎁
    But Santa's elves are still working on this, it should arrive in ~30 minutes and Santa would be thankful for feedback 🎅
    Thanks 😉

  7. marichka-spin commented on Dec 23, 2021

    @marichka-spin
    Author

    @meistermeier thank you for the fix. I'm still testing. Are you interested in other issues I may notice during my work? Anyway I'm using neo4j and Neo4j Spring Data actively.

  8. meistermeier commented on Dec 23, 2021

    @meistermeier
    Collaborator

    Great, thanks for the feedback.
    Of course we are interested in the issues, you have to report.

  9. added this to the 6.1.8 (2021.0.8) milestone on Dec 23, 2021
  10. added 2 commits that reference this issue on Dec 23, 2021
  11. marichka-spin commented on Dec 23, 2021

    @marichka-spin
    Author

    @meistermeier Thank you! Finally I've finished testing the new fix! Looks good! Looking forward for release!

  12. added a commit that references this issue on Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions