Hello,
I am trying to get Projections to work, as I want to load only some data from neo4j and not all nested relationships and nodes. I got everything to work so far except "Pages".
Consider following example:
Entity:
@Node(primaryLabel = "Entity")
public class Entity {
@Property(name = some_property)
private String someProperty;
@Relationship(type = "some_rel", direction = Relationship.Direction.OUTGOING)
private List<Entity2> otherEntities;
Projection:
@Value //lombok
public class Entity {
String someProperty;
Repository:
public interface EntityRepository extends Neo4jRepository<Entity, Long> {
Optional<MyProjection> findBySomeProperty(String someProperty);
Page<MyProjection> findAllProjectedBy(Pageable pageable);
}
Now calling findBySomeProperty("value")
works like a charm and the related entities do not have to be loaded from the neo4j database (at least I hope so, as this is the goal of projections)
But calling findAllProjectedBy(PageRequest.of(0,20)
throws an unexpected error:
java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class org.springframework.data.neo4j.repository.query.EntityInstanceWithSource (java.util.ArrayList is in module java.base of loader 'bootstrap'; org.springframework.data.neo4j.repository.query.EntityInstanceWithSource is in unnamed module of loader 'app')
at org.springframework.data.neo4j.repository.query.AbstractNeo4jQuery.lambda$execute$2(AbstractNeo4jQuery.java:94) ~[spring-data-neo4j-6.0.3.jar:6.0.3]
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter.convert(ResultProcessor.java:236) ~[spring-data-commons-2.4.3.jar:2.4.3]
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter.lambda$and$0(ResultProcessor.java:222) ~[spring-data-commons-2.4.3.jar:2.4.3]
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter.convert(ResultProcessor.java:236) ~[spring-data-commons-2.4.3.jar:2.4.3]
at org.springframework.data.repository.query.ResultProcessor.processResult(ResultProcessor.java:170) ~[spring-data-commons-2.4.3.jar:2.4.3]
at org.springframework.data.neo4j.repository.query.AbstractNeo4jQuery.execute(AbstractNeo4jQuery.java:97) ~[spring-data-neo4j-6.0.3.jar:6.0.3]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137) ~[spring-data-commons-2.4.3.jar:2.4.3]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121) ~[spring-data-commons-2.4.3.jar:2.4.3]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152) ~[spring-data-commons-2.4.3.jar:2.4.3]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:131) ~[spring-data-commons-2.4.3.jar:2.4.3]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80) ~[spring-data-commons-2.4.3.jar:2.4.3]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-5.3.3.jar:5.3.3]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[spring-tx-5.3.3.jar:5.3.3]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-5.3.3.jar:5.3.3]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-5.3.3.jar:5.3.3]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.3.jar:5.3.3]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.3.jar:5.3.3]
at com.sun.proxy.$Proxy128.findAllProjectedBy(Unknown Source) ~[na:na]
Maybe someone can tell me what I did wrong or how it is supposed to work.
Thank you.