Hi, I'm running into a weird problem.
Specifically, I have defined an interface-based projection to retrieve a view of a persisted entity (as per https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#projections.interfaces) from the database through a custom query (which according to this: https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#faq.custom-queries-and-custom-mappings shouldn't be a problem, given I don't use this query to write but only to read from the db). However, when I try to run the query from the backend, I get the following error:
org.springframework.data.neo4j.core.mapping.NoRootNodeMappingException: Could not find mappable nodes or relationships inside Record <{name: "Sara", age: 27, sex: "M", occupation: "Worker"}> for org.springframework.data.neo4j.core.mapping.DefaultNeo4jPersistentEntity@30aec673
Here is my custom query (inside a Neo4j Spring repository with root entity Student):
@Query("MATCH (students:Students)-[:LIKES]->()<-[:TEACHES]-(teacher: Teacher {email : $email}) "
+ "WHERE NOT (teacher)-->(students) "
+ "RETURN DISTINCT students.name, students.age, students.sex, students.occupation")
List<StudentCandidate> findUnmetLikingStudents(String email);
here is my StudentCandidate (the projection interface):
public interface StudentCandidate {
String getName();
int getAge();
String getSex();
String getOccupation();
}
and here's my Student class (with most details edited out for brevity's sake):
@Node
public class Student extends Person implements Positionable {
@Id
private String id;
private double latitude;
private double longitude;
private int maxDistance;
private Sex roommateSex;
private int roommateAge;
public Student(String username, String password, boolean enabled, boolean accountNonExpired,
boolean credentialsNonExpired, boolean accountNonLocked, String email, String name, int age,
String sex, String occupation, double latitude, double longitude, int maxDistance, String roommateSex, int roommateAge) {
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked,
new HashSet<>(Arrays.asList(new UserAuthority(UserRole.STUDENT))), email, name, age, sex,
occupation);
id = UUID.randomUUID().toString();
this.latitude = latitude;
this.longitude = longitude;
this.maxDistance = maxDistance;
this.setRoommateSex(roommateSex);
this.roommateAge = roommateAge;
}
as you may see, some properties (including those in the interface projection) are actually set in the Person superclass (N.B. they're still called the same, i.e. "name", "age", "sex" and "occupation". Also, "sex" and "occupation" are enumerations, but even when I set the corresponding accessor return types in StudentCandidate to the enumerations - rather than String -, I get the same error). I don't know if that's relevant.
Is there something I'm doing wrong or is this functionality not actually supported?