cassandra查询无法解析获取数据

7eumitmz  于 2021-06-15  发布在  Cassandra
关注(0)|答案(1)|浏览(386)

我的personrepository中有一个查询,如下所示:

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

(其中keysp是我的keyspace,person是表名)
我的个人实体是:

@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;
    }
    }

我的个人背景是:

@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;
    }

}

堆栈跟踪:

java.lang.NullPointerException
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.selectOne(CassandraTemplate.java:644)
at org.springframework.data.cassandra.core.CassandraTemplate.selectOne(CassandraTemplate.java:509)
at org.springframework.data.cassandra.repository.query.CassandraQueryExecution$SingleEntityExecution.execute(CassandraQueryExecution.java:104)
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.$Proxy144.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.$Proxy144.findByResource(Unknown Source)
at MyProject.service.StatisticsCacheService.storeDataInternal(StatisticsCacheService.java:41)
at MyProject.service.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)

我认为问题是查询从数据库获取数据,但无法将其解析为我的person实体,这可能是因为person有一个复合主键 PersonContext context . 我这么说是因为如果我将personcontext中的所有内容添加到person实体中,同样的查询也可以正常工作。
cqlsh中的表desc是:

CREATE TABLE haltdos.statistics (
    joinTime varint,
    category text,
    personid text,
    address text,
    PRIMARY KEY (joinTime, category, personid)
) WITH CLUSTERING ORDER BY (category ASC, personid ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

我想用personcontext。请帮帮我。谢谢
我用Spring Boot。

krcsximq

krcsximq1#

发现这个问题的答案是我的实体定义。
所有细节都可以在这里找到。

相关问题