项目详情
我正在使用Kotlin跟踪这些文档Spring data Neo4j,我正在努力从存储库查询中返回关系:
数据库布局
我有一个User
节点和一个Skill
节点,关系如下:
实体
技能
@Node
data class Skill(
@Id
val uid: UUID,
val title: String,
) {
constructor(title: String) : this(UidGenerator.makeOne(), title)
}
用户
@Node
data class User(
@Id
var uid: UUID,
@Relationship(type = "DEMONSTRATES")
val demonstrates: List<Demonstrates>,
val firstName: String,
val lastName: String,
) {
constructor(demonstrates: List<Demonstrates>, firstName: String, lastName: String)
: this(UidGenerator.makeOne(), demonstrates, firstName, lastName)
}
关系属性
@RelationshipProperties
data class Demonstrates(
@TargetNode
val skill: Skill,
val rating: Int,
)
我遇到的问题
当我注入以下存储库并调用getDemonstrationList
时,我收到以下错误。
@Repository
interface MyRepository : Neo4jRepository<Skill, UUID> {
@Query("""
MATCH (:User)-[d:DEMONSTRATES]->(:Skill) RETURN d
""")
fun getDemonstrationList(): List<Demonstrates>
}
Caused by: org.springframework.data.neo4j.core.mapping.NoRootNodeMappingException: Could not find mappable nodes or relationships inside Record<{d: relationship<4>}> for org.springframework.data.neo4j.core.mapping.DefaultNeo4jPersistentEntity@750a04ec
at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.read(DefaultNeo4jEntityConverter.java:106) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.core.mapping.DefaultNeo4jEntityConverter.read(DefaultNeo4jEntityConverter.java:67) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.core.mapping.Schema.lambda$getRequiredMappingFunctionFor$0(Schema.java:96) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.repository.query.Neo4jQuerySupport.lambda$getMappingFunction$0(Neo4jQuerySupport.java:105) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.core.PreparedQuery$AggregatingMappingFunction.apply(PreparedQuery.java:218) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.core.PreparedQuery$AggregatingMappingFunction.apply(PreparedQuery.java:154) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.core.DelegatingMappingFunctionWithNullCheck.apply(DelegatingMappingFunctionWithNullCheck.java:45) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.core.DelegatingMappingFunctionWithNullCheck.apply(DelegatingMappingFunctionWithNullCheck.java:35) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.core.DefaultNeo4jClient$DefaultRecordFetchSpec.lambda$partialMappingFunction$0(DefaultNeo4jClient.java:325) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na]
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) ~[na:na]
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na]
at org.springframework.data.neo4j.core.DefaultNeo4jClient$DefaultRecordFetchSpec.all(DefaultNeo4jClient.java:312) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.core.Neo4jTemplate$DefaultExecutableQuery.getResults(Neo4jTemplate.java:575) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.repository.query.Neo4jQueryExecution$DefaultQueryExecution.execute(Neo4jQueryExecution.java:51) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.neo4j.repository.query.AbstractNeo4jQuery.execute(AbstractNeo4jQuery.java:85) ~[spring-data-neo4j-6.0.2.jar:6.0.2]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137) ~[spring-data-commons-2.4.2.jar:2.4.2]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121) ~[spring-data-commons-2.4.2.jar:2.4.2]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152) ~[spring-data-commons-2.4.2.jar:2.4.2]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:131) ~[spring-data-commons-2.4.2.jar:2.4.2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.2.jar:5.3.2]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80) ~[spring-data-commons-2.4.2.jar:2.4.2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.2.jar:5.3.2]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-5.3.2.jar:5.3.2]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[spring-tx-5.3.2.jar:5.3.2]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-5.3.2.jar:5.3.2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.2.jar:5.3.2]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-5.3.2.jar:5.3.2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.2.jar:5.3.2]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.2.jar:5.3.2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.2.jar:5.3.2]
at org.springframework.data.repository.core.support.MethodInvocationValidator.invoke(MethodInvocationValidator.java:98) ~[spring-data-commons-2.4.2.jar:2.4.2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.2.jar:5.3.2]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.2.jar:5.3.2]
at com.sun.proxy.$Proxy68.getDemonstrationIds(Unknown Source) ~[na:na]
at com.ntr.neo4j.Neo4jApplication.run(Neo4jApplication.kt:44) ~[classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804) ~[spring-boot-2.4.1.jar:2.4.1]
... 5 common frames omitted
我的问题
我对Kotlin和Neo4j非常陌生,但我确实了解Spring框架。据我所知,存储库无法计算出它需要根据我的查询结果创建Demonstrates
示例列表。我对从关系中删除rating
属性很感兴趣,但教程并不是很清楚我如何做到这一点。为了让我的查询返回Demonstrates
的列表,请让我知道我遗漏了什么?
1条答案
按热度按时间6kkfgxo01#
从Spring data Neo4j6开始,Relationship不能再是顶级实体。
因此,您的存储库方法必须返回
Skill
、SomeCollection<Skill>
(其中SomeCollection
可以是List
、Set
、Flux
、Page
等)。您还可以返回基于Skill
的投影,但不能基于@RelationshipProperties
注解的类。