cassandra查询不返回任何数据

ctrmrzij  于 2021-06-15  发布在  Cassandra
关注(0)|答案(0)|浏览(280)

我正在使用cassandra存储库从数据库中获取数据。我使用以下查询(尽可能简单):

public interface PersonReposiroty extends CassandraRepository<Person>
    @Query("SELECT * FROM KeySp.person WHERE joinTime >= 21 ALLOW FILTERING")
    public List<Person> findByTime();
}

当java语句调用它时:

List<Person> persons = repository.findByTime();

它产生一个 NullPointerException .
实际上,任何应该从数据库返回任何数据的查询都会显示异常。
同时 Update , Delete , Save 当使用上述存储库实现时,函数可以完美地工作。
请告诉我哪里做错了,怎么做(我用 Spring Boot )
提前谢谢。
我的个人实体是:

@Entity
@Table(name = "person", indexes = { @Index(name="peson_index", columnList = "joinTime, category, personId") })
public class Person {

    @Id
    @PrimaryKeyColumn
    private PersonContext context;

    @Column(name = "address", columnDefinition = "LONGTEXT")
    private String address;

    public PersonContext getContext() {
        return context;
    }

    public void setContext(PersonContext context) {
        this.context = context;
    }

    public String getAddress() {
        return adress;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}

personcontext.java是

@Embeddable
@PrimaryKeyClass
public class PersonContext implements Serializable {

    private static final long serialVersionUID = 3L;

    @NotNull
    @PrimaryKeyColumn(name = "joinTime", type = PrimaryKeyType.PARTITIONED)
    private long joinTime;

    @NotNull
    @Column(name = "category")
    private String category;

    @Column(name = "person_id", length = 50)
    private String personId = StringUtils.EMPTY;

    public long getjoinTime() {
        return joinTime;
    }

    public void setjoinTime(long joinTime) {
        this.joinTime = joinTime;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getPersonId() {
        return personId;
    }

    public void setPersonId(String personId) {
        this.personId = personId;
    }

}
堆栈跟踪:

ForgivingExceptionHandler: Consumer com.User.service.CacheService$1@6e6c7b7a (amq.ctag-6VuMjQcL3vjdfed2yC78zA) method handleDelivery for channel AMQChannel(amqp://user@155.83.167.923:5672/,1) threw an exception for channel AMQChannel(amqp://guest@159.89.169.123:5672/,1)
java.lang.NullPointerException: null
    at org.springframework.data.cassandra.convert.MappingCassandraConverter.readProperty(MappingCassandraConverter.java:259)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter$1.doWithPersistentProperty(MappingCassandraConverter.java:233)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter$1.doWithPersistentProperty(MappingCassandraConverter.java:229)
    at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:330)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter.readProperties(MappingCassandraConverter.java:229)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter.readPropertiesFromRow(MappingCassandraConverter.java:223)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter.readEntityFromRow(MappingCassandraConverter.java:190)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter.readRow(MappingCassandraConverter.java:176)
    at org.springframework.data.cassandra.convert.MappingCassandraConverter.read(MappingCassandraConverter.java:298)
    at org.springframework.data.cassandra.core.CassandraConverterRowCallback.doWith(CassandraConverterRowCallback.java:47)
    at org.springframework.data.cassandra.core.CassandraTemplate.processResultSet(CassandraTemplate.java:605)
    at org.springframework.data.cassandra.core.CassandraTemplate.select(CassandraTemplate.java:594)
    at org.springframework.data.cassandra.core.CassandraTemplate.select(CassandraTemplate.java:376)
    at org.springframework.data.cassandra.repository.query.CassandraQueryExecution$CollectionExecution.execute(CassandraQueryExecution.java:85)
    at org.springframework.data.cassandra.repository.query.CassandraQueryExecution$ResultProcessingExecution.execute(CassandraQueryExecution.java:143)
    at org.springframework.data.cassandra.repository.query.AbstractCassandraQuery.execute(AbstractCassandraQuery.java:113)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:483)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56)
    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.$Proxy142.findByResource(Unknown Source)
    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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy142.findByTime()
    at User.StatisticsCacheService.storeDataInternal(StatisticsCacheService.java:46)
    at User.CacheService$1.handleDelivery(CacheService.java:54)
    at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)
    at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
2018-10-31 13:02:48,193 ERROR [User-scheduler-2] TaskUtils$LoggingErrorHandler: Unexpected error occurred in scheduled task.
com.rabbitmq.client.AlreadyClosedException: channel is already closed due to clean channel shutdown; protocol method: #method<channel.close>(reply-code=200, reply-text=Closed due to exception from Consumer (amq.ctag-6VuMjQcL3vjdfed2yC78zA) method handleDelivery for channel AMQChannel(amqp://guest@159.89.169.123:5672/,1), class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:253)
    at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:336)
    at com.rabbitmq.client.impl.ChannelN.basicConsume(ChannelN.java:1365)
    at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicConsume(AutorecoveringChannel.java:540)
    at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicConsume(AutorecoveringChannel.java:494)
    at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicConsume(AutorecoveringChannel.java:472)
    at User.service.CacheService.cacheDataInternal(CacheService.java:59)
    at User.service.periodic.StatisticsCacheService.cacheData(StatisticsCacheService.java:56)
    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.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题