Spring Data Cassandra反应-自定义删除方法

时间:2018-11-08 11:50:35

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

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

这是我的方法。注意Mono返回类型。它与春季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代替returntype无效。它只是返回对象而不删除它。

我想念什么吗?

1 个答案:

答案 0 :(得分:0)

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

public interface RegistrationRepository extends ReactiveCrudRepository<RegistrationEntity, MapId> {

}