Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-01-2021 03:48 AM
Hello,
I have the following issue (SDN 6.1.5 and 6.2.0-SNAPSHOT) when executing a query returning a projection
java.lang.ClassCastException:
Cannot cast org.springframework.data.neo4j.integration.movies.shared.Movie
to
org.springframework.data.neo4j.integration.movies.imperative.AdvancedMappingIT$MovieRefProjectionClass
The error happens when using classes (and not interfaces) for the projection and when the projection class has a field pointing to a projection class.
Sample projection class (using the testcase from SDN):
static class MovieWithSequelProjectionClass {
private String title;
private MovieWithSequelProjectionClass sequel;
public MovieWithSequelProjectionClass getSequel() {
return sequel;
}
public void setSequel(MovieWithSequelProjectionClass sequel) {
this.sequel = sequel;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
Please note that we don't have this issue when using projection interfaces.
Steps to reproduce:
Should I open an issue on github ?
Thanks
Solved! Go to Solution.
10-11-2021 06:12 AM
For a class-based / DTO projection this is not possible.
The problem is that Spring Data (Neo4j) is only aware of the already mapped information, in this case Movie
.
Now it wants to transfer this into the projection class that expects the projection class instead of just Movie
and it fails.
This is also mentioned in the documentation.
These DTO types can be used in exactly the same way projection interfaces are used, except that no proxying happens and no nested projections can be applied.
10-11-2021 06:12 AM
For a class-based / DTO projection this is not possible.
The problem is that Spring Data (Neo4j) is only aware of the already mapped information, in this case Movie
.
Now it wants to transfer this into the projection class that expects the projection class instead of just Movie
and it fails.
This is also mentioned in the documentation.
These DTO types can be used in exactly the same way projection interfaces are used, except that no proxying happens and no nested projections can be applied.
All the sessions of the conference are now available online