@Index属性的Spring数据Neo4j和InvalidDataAccessApiUsageException
我已将uuid属性添加到我的SDN 4基本实体中,因此现在它看起来像:@Index属性的Spring数据Neo4j和InvalidDataAccessApiUsageException,neo4j,spring-data-neo4j-4,neo4j-ogm,Neo4j,Spring Data Neo4j 4,Neo4j Ogm,我已将uuid属性添加到我的SDN 4基本实体中,因此现在它看起来像: @NodeEntity public abstract class BaseEntity { @GraphId private Long id; @Index(unique = true, primary = true) private String uuid; ... } 现在我的一些测试停止了 我有一个可注释的抽象类: @NodeEntity public abstract cl
@NodeEntity
public abstract class BaseEntity {
@GraphId
private Long id;
@Index(unique = true, primary = true)
private String uuid;
...
}
现在我的一些测试停止了
我有一个可注释的
抽象类:
@NodeEntity
public abstract class Commentable extends BaseEntity {
private final static String COMMENTED_ON = "COMMENTED_ON";
@Relationship(type = COMMENTED_ON, direction = Relationship.INCOMING)
private Set<Comment> comments = new HashSet<>();
public Set<Comment> getComments() {
return comments;
}
public void addComment(Comment comment) {
if (comment != null) {
comments.add(comment);
}
}
public void removeComment(Comment comment) {
comments.remove(comment);
}
}
等
这是我的SDN4存储库
@Repository
public interface CommentableRepository extends GraphRepository<Commentable> {
}
如果commentableId是决策id或产品id,则它将失败,出现以下异常:
org.springframework.dao.InvalidDataAccessApiUsageException: Supplied id does not match primary index type on supplied class.; nested exception is org.neo4j.ogm.session.Neo4jException: Supplied id does not match primary index type on supplied class.
at org.springframework.data.neo4j.transaction.SessionFactoryUtils.convertOgmAccessException(SessionFactoryUtils.java:154)
at org.springframework.data.neo4j.repository.support.SessionBeanDefinitionRegistrarPostProcessor.translateExceptionIfPossible(SessionBeanDefinitionRegistrarPostProcessor.java:71)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy175.findOne(Unknown Source)
但是如果我从我的BaseEntity.uuid
字段中删除@Index(unique=true,primary=true)
,一切都会正常工作
如何解决此问题?您使用了错误的
存储库GraphRespository
是一个遗留实现。新的实现称为Neo4jRepository
尝试:
public interface CommentableRepository扩展了Neo4jRepository{
...
}
关键区别在于第二个参数化类型,即用于域类的ID
类型;在这种情况下,String uuid
您使用了错误的存储库
GraphRespository
是一个遗留实现。新的实现称为Neo4jRepository
尝试:
public interface CommentableRepository扩展了Neo4jRepository{
...
}
关键区别在于第二个参数化类型,即用于域类的ID
类型;在本例中,字符串uuid
谢谢您的回答。我已将我的repo更改为CommentableRepository extends Neo4jRepository
not String。。因为我仍然使用Long(@GraphId-private-Long-id;
)作为id,但问题并没有消失。@GraphId
的内容仍然存在混淆@GraphId
与存储库
s无关。将其更改为String
,它就会工作。谢谢。我很困惑,@GraphId
不是域类使用的ID吗?就我而言,我没有uuid。为什么我要设置
而不是
?谢谢你的回答。我已将我的repo更改为CommentableRepository extends Neo4jRepository
not String。。因为我仍然使用Long(@GraphId-private-Long-id;
)作为id,但问题并没有消失。@GraphId
的内容仍然存在混淆@GraphId
与存储库
s无关。将其更改为String
,它就会工作。谢谢。我很困惑,@GraphId
不是域类使用的ID吗?就我而言,我没有uuid。为什么我要设置
而不是
?
commentableRepository.findOne(commentableId);
org.springframework.dao.InvalidDataAccessApiUsageException: Supplied id does not match primary index type on supplied class.; nested exception is org.neo4j.ogm.session.Neo4jException: Supplied id does not match primary index type on supplied class.
at org.springframework.data.neo4j.transaction.SessionFactoryUtils.convertOgmAccessException(SessionFactoryUtils.java:154)
at org.springframework.data.neo4j.repository.support.SessionBeanDefinitionRegistrarPostProcessor.translateExceptionIfPossible(SessionBeanDefinitionRegistrarPostProcessor.java:71)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy175.findOne(Unknown Source)
public interface CommentableRepository extends Neo4jRepository<Commentable, String> {
...
}