spring data cassandra reactive - 自定义删除方法

spring data cassandra reactive - custom delete method

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

这是我的方法。注意 Mono return 类型。它与 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(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.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 替换 returntype 不起作用。它只是 return 对象而不删除它。

我是不是漏掉了什么?

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

public interface RegistrationRepository extends ReactiveCrudRepository<RegistrationEntity, MapId> {

}