I have a Pet
class with sub-classes Dog
and Cat
. Dog
and Cat
have different relationships to other classes. Is it possible to retrieve these different relationships from the repository class, PetRepository
? I've set it up like below (sample project at https://github.com/aldrinm/sdn-hierarchy),
@Node("Pet")
public abstract class Pet {
@Id
@GeneratedValue
private Long id;
private String name;
//...getters, etc.
}
@Node("Cat")
public class Cat extends Pet {
@Relationship(value = "SLEEP_SPOT", direction = Relationship.Direction.OUTGOING)
private List<SleepSpot> sleepSpots;
//...getters, etc.
}
@Node("Dog")
public class Dog extends Pet {
@Relationship(value = "CHEW_TOY", direction = Relationship.Direction.OUTGOING)
private List<ChewToy> chewToys;
//...getters, etc.
}
and the repository,
public interface PetRepository extends Neo4jRepository<Pet, Long> {
@Query("MATCH (a:Pet) RETURN a")
List<Pet> findAllPets();
}
I would like findAllPets
to hydrate the chewToys
and sleepSpots
automatically. Currently, it doesn't retrieve any nodes along these sub-class relationships.
What would be the best way to retrieve all the pet details including specific information from it's sub-classes ?
(sample code is https://github.com/aldrinm/sdn-hierarchy)
Thanks