Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-02-2022 04:54 PM
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.
Solved! Go to Solution.
09-08-2022 05:44 AM
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/s...)
09-06-2022 01:44 AM
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
09-07-2022 06:06 PM
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);
09-08-2022 05:44 AM
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/s...)
09-19-2022 07:41 PM
@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.
10-01-2022 01:31 AM
@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.
All the sessions of the conference are now available online