Saving Interface based Projections

Is it possible to save Interface based Projections?

Can't see anything in the documentation saying you can't, but getting the following error when I try:

org.springframework.data.mapping.MappingException: Constructor parameter names aren't available, please recompile your domain.

Yes, this possible. Did you have a look at the documentation? https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#projections or more specific for saving through the Neo4jTemplate: https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#projections.sdn.persistence

Ah, ok. I think the basic problem is, that you are trying to persist an interface instead of a DTO with this call chain.
And now the exception make sense to me. You cannot create an instance of an interface (this easy) and it would not make any sense in this case, because the interface projection is in general a read-only representation.

An example for DTO (https://github.com/spring-projects/spring-data-neo4j/blob/0e055f96d01dd30ad157d4c1052e3ce81a421025/src/test/java/org/springframework/data/neo4j/integration/issues/gh2474/GH2474IT.java#L151)

Yes read through the document.

Interface based projections work fine UNTIL I try and persist changes.

Class based projections allow me to persist.

neo4jTemplate.save(MyEntity.class).one(myInterfaceInstance);

@gerrit_meier Thanks for the reply. Thats what I had assumed but couldn't find it stated in the doco, so thanks for verifying.

Looking at that example dto you posted I see it uses a multi level projection for mayor, citizens and cityEmployees. I've had no luck getting this to work in my project with class based projections, and get a ClassCastException when I load the projection using the repository: Cannot cast MyEntity to MyProjection.

@gerrit_meier Any chance you can help with some direction on my other question. Trying to plan migration to latest version, and trying to get my head around best approach to use projections to limit the amount of graph that gets loaded.

https://community.neo4j.com/t5/drivers-stacks/classcastexception-using-multi-level-projection/td-p/60672