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.

SDN6: ClassCastException when projecting relations (with classes)

gonzalad
Node Link

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

1 ACCEPTED SOLUTION

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.

View solution in original post

1 REPLY 1

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.