Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-11-2021 08:34 AM
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.
03-22-2021 04:58 AM
Still trying to solve this issue. Any help?
03-25-2021 05:00 AM
Sorry for the delay.
I tried to reproduce your problem with Spring Boot 2.4.4 (Spring Data Neo4j 6.0.6 / current) and 2.4.3 (6.0.5) but could not find a problem. Maybe you can have a look at neo4j-issues-examples/c-35084 at master · meistermeier/neo4j-issues-examples · GitHub and tell me if there is something different in your code. I tried to keep it as close as possible to the given example.
03-25-2021 07:57 AM
Thank you a lot!
I was using Spring Boot 2.4.2.
I downloaded your example and it worked. When I changed the Spring Boot version in your example back to 2.4.2, it threw the same error that I posted above.
I never thought changing from 2.4.2 to 2.4.4 would do the trick.
03-26-2021 12:39 AM
And now that you are saying this, I remember that there was something around pageables and projections that got fixed.
All the sessions of the conference are now available online