cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

OGM: Issues with polymorphism and @Relationship collections

Martin
Node Link

Hi,
I have been struggling for a while to use the ogm-driver to load relationships of collections of child classes.

    @Relationship(type = "HAS_INGREDIENT")
    Set<Ingredient> ingredients;

When instantiated to contain some objects that inherit from Ingredient, those child objects relationships won't load.

@NodeEntity
public class Strawberry extends Ingredient {

    @Relationship(type = "TASTES_LIKE")
    Flavor flavor;
}

public class Ice extends Ingredient {

    @Relationship(type = "HAS_TEMPERATURE")
    Temperature temperature;
}

The properties and labels of the Ice/Strawberry nodes load just fine from the graph, but not their relationships. Is there a way to make this work?
Example project:

2 REPLIES 2

I have this exact same use case. Any updates?

I think this is related to the general problem of inheritance.You can't use base type to model all relationship in inheritance hierarchy.You can include them in a Set but if you want to invoke a specific relationship you need to invoke language features like instanceof and then map it to specific type.