Skip to content

Mapping of nested classes collected under common label #2462

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
marichka-spin opened this issue Jan 12, 2022 · 5 comments
Closed

Mapping of nested classes collected under common label #2462

marichka-spin opened this issue Jan 12, 2022 · 5 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@marichka-spin
Copy link

Hello, team!

I have a question regarding inheritance again. For Example there is the following architecture:

@Getter
@Setter
@Node("Base")
public abstract class BaseClass {

    @Id
    private String uuid;
}

@Getter
@Setter
@Node("PetOwner")
public abstract class PetOwner extends BaseClass {

    private String name;

    @Relationship(type = "hasPet")
    private List<Animal> pets;
}

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

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

@Getter
@Setter
@Node("Animal")
public abstract class Animal extends BaseClass {

    private String name;
}

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

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

public interface BaseClassRepository extends Neo4jRepository<BaseClass, String> {
}

I have a use case when I need to get the collection of all entities that are subclassed from BaseClass. With OGM I was able to execute the following query and have everything mapped correctly.

MATCH (n:Base) RETURN n, [(n)-[r]->(b) | [r,b]]

But now the cypher response has increased significantly and not totally correct. It doesn't expect to cover even this simple inheritance scheme described in first code block.

Please take a look at my unit tests in the repository https://github.com/idun-corp/neo4j-test (Test PetOwnerNeo4jServiceTest.testGetAllWithRelations)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 12, 2022
@marichka-spin marichka-spin changed the title Mapping of nested classes cloccted under common label Mapping of nested classes collected under common label Jan 12, 2022
@meistermeier meistermeier self-assigned this Jan 13, 2022
@meistermeier
Copy link
Collaborator

This is not as simple as you might think in the first place 😉 but challenge accepted.
Some background information on this:
The query generator uses the BaseClass because of the BaseClassRepository as the main type. It has 0 relationship definitions. Only the PetOwner as an abstract, inheriting class has. But in the mapping code, SDN finds the implementation of those abstract hierarchy in Boy and Girl.
So this gives a lot of room for searching for relationships. But as I said, I think this is a great opportunity for us to broaden the mapping capabilities of SDN.

@meistermeier meistermeier added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 13, 2022
@marichka-spin
Copy link
Author

Yeah, I didn't have even the smallest thought that it is simple. I've debugged some classes of SDN that are responsible for mappings and I totally understand why it works this way. And it is just a suggestion for you broad the vision on the possible use cases. I have already spent a lot of hours trying to migrate our code from OGM (that is not supported anymore) to SDN. I think I'll be able to cope with this particular case (and yeah its complicated :) ). And thank you for the response and have a nice day.

meistermeier added a commit that referenced this issue Jan 14, 2022
meistermeier added a commit that referenced this issue Jan 14, 2022
meistermeier added a commit that referenced this issue Jan 14, 2022
@meistermeier
Copy link
Collaborator

Could you give 6.3.0-GH-2462-SNAPSHOT a try?
It's not a sophisticated solution yet but it technical works.

@marichka-spin
Copy link
Author

Brilliant!!! Its working!!! Many thanks!!!!

@meistermeier
Copy link
Collaborator

Thanks for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants