【问题标题】:spring data cassandra reactive - custom delete methodspring data cassandra reactive - 自定义删除方法
【发布时间】:2019-04-11 22:16:25
【问题描述】:

我目前正在尝试在我的 ReactiveCrudRepository 中指定一个删除方法。有预定义的删除方法可以按预期工作。但是我的主键名为 msisdn 而不是 id 所以我需要定义一个自定义方法来通过这个键删除条目。

这是我的方法。注意 Mono 返回类型。它与 spring 中的 ReactiveCrudRepository 使用的相同

public interface RegistrationRepository extends ReactiveCrudRepository<RegistrationEntity, String> {

    Mono<RegistrationEntity> findByMsisdn(String msisdn);

    Mono<Void> deleteByMsisdn(String msisdn);
}

我写了一个简单的测试,其中测试数据持久保存在内存中的 cassandra 实例中,然后我尝试删除该条目。但我得到以下异常:

org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type class java.lang.Void!

    at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:79)
    at org.springframework.data.cassandra.repository.query.DtoInstantiatingConverter.<init>(DtoInstantiatingConverter.java:64)
    at org.springframework.data.cassandra.repository.query.ReactiveCassandraQueryExecution$ResultProcessingConverter.convert(ReactiveCassandraQueryExecution.java:229)
    at org.springframework.data.cassandra.repository.query.ReactiveCassandraQueryExecution$ResultProcessingExecution.execute(ReactiveCassandraQueryExecution.java:196)
    at org.springframework.data.cassandra.repository.query.AbstractReactiveCassandraQuery.executeNow(AbstractReactiveCassandraQuery.java:110)
    at org.springframework.data.cassandra.repository.query.AbstractReactiveCassandraQuery.execute(AbstractReactiveCassandraQuery.java:82)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy45.deleteByMsisdn(Unknown Source)
    at ch.sbb.kat.fc.service.CassandraRepositoryTest.deleteTest(CassandraRepositoryTest.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

用 Mono 替换返回类型不起作用。它只是返回对象而不删除它。

我错过了什么吗?

【问题讨论】:

    标签: spring spring-data spring-data-cassandra


    【解决方案1】:

    我的解决方案是使用MapId 而不是String

    public interface RegistrationRepository extends ReactiveCrudRepository<RegistrationEntity, MapId> {
    
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-29
      • 2019-06-05
      • 1970-01-01
      • 2017-03-06
      • 2017-03-26
      • 2017-06-18
      • 2017-01-29
      • 1970-01-01
      • 2020-12-02
      相关资源
      最近更新 更多