Closed
Description
In SDN, if you have the following nodes and relationships:
public abstract class MyEntity<T extends MyEntity<T>> {
@Id
@Property(name = "id")
@GeneratedValue(value = MyStrategy.class)
protected String id;
}
@Getter
@Setter
@NoArgsConstrcutor
@AllArgsConstructor
@Node(value = "Person")
public class Person extends MyEntity {
@Property(value = "name")
private String name;
@Property(value = "age")
private int age;
}
@Getter
@Setter
@NoArgsConstrcutor
@AllArgsConstructor
@Node(value = "Dog")
public class Dog extends MyEntity {
@Property(value = "name")
private String name;
@Relationship(value = "IS_PET", direction = Direction.OUTGOING)
private Person owner;
}
If a person has no pets directed towards it and you have the following pet repository:
@Repository
public interface DogRepository extends Neo4jRepository<Dog, String> {
Query(“MATCH(person:Person {id: $id}) “
+ “OPTIONAL MATCH (person)<-[:IS_PET]-(dog:Dog) “
+ “RETURN dog;”)
List<Dog> getDogsForPerson(String id);
}
SDN will fail the correctly map the Collection
of Dog
for the getDogsForPerson
method due to the dog node coming back as null
. This did work correctly in OGM.
If you do the following, this does appear to make it work, though this seems not to be the expected behavior with the root node being returned from Neo4J and it may also cause unintended issues:
@Repository
public interface DogRepository extends Neo4jRepository<Dog, String> {
Query(“MATCH(person:Person {id: $id}) “
+ “OPTIONAL MATCH (person)<-[:IS_PET]-(dog:Dog) “
+ “RETURN collect(dog);”)
List<Dog> getDogsForPerson(String id);
}