我在CQL中为Cassandra创建了两个表。 我使用org.springframework.data.cassandra.repository.CassandraRepository。
在一个表(memobox)中,repository.findAll();可以成功获得, 在其他表(departments)中,repository.findAll();无法成功获取,并输出以下错误。
有什么好建议吗?
■项目结构
Apache Cassandra的SpringBoot + Spring数据
版本:
■错误日志
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_74]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_74]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_74]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_74]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:76) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.convert.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:83) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.readEntityFromRow(MappingCassandraConverter.java:133) ~[spring-data-cassandra-1.3.5.RELEASE.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.readRow(MappingCassandraConverter.java:115) ~[spring-data-cassandra-1.3.5.RELEASE.jar:na]
at org.springframework.data.cassandra.convert.MappingCassandraConverter.read(MappingCassandraConverter.java:200) ~[spring-data-cassandra-1.3.5.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraConverterRowCallback.doWith(CassandraConverterRowCallback.java:47) ~[spring-data-cassandra-1.3.5.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.select(CassandraTemplate.java:565) ~[spring-data-cassandra-1.3.5.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.select(CassandraTemplate.java:328) ~[spring-data-cassandra-1.3.5.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.selectAll(CassandraTemplate.java:311) ~[spring-data-cassandra-1.3.5.RELEASE.jar:na]
at org.springframework.data.cassandra.repository.support.SimpleCassandraRepository.findAll(SimpleCassandraRepository.java:104) ~[spring-data-cassandra-1.3.5.RELEASE.jar:na]
at org.springframework.data.cassandra.repository.support.SimpleCassandraRepository.findAll(SimpleCassandraRepository.java:36) ~[spring-data-cassandra-1.3.5.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74]
■成功的表:描述memobox
cqlsh:keyspacea> describe memobox;
CREATE TABLE keyspacea.memobox (
id timeuuid PRIMARY KEY,
date timestamp,
memo text,
name text
) WITH 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'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
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 = '99.0PERCENTILE';
CREATE INDEX memobox_memo ON keyspacea.memobox (memo);
CREATE INDEX memobox_name ON keyspacea.memobox (name);
■表不成功:描述部门
cqlsh:keyspacea> describe departments;
CREATE TABLE keyspacea.departments (
department_id varint PRIMARY KEY,
department_name text
) WITH 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'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
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 = '99.0PERCENTILE';
■来源低于
https://github.com/hidetarou2013/SpringBootDBSample
分支是feature / cassandra
■实体:MemoBox
package com.example.cassandra.entity;
import java.util.Date;
import java.util.UUID;
import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.data.cassandra.mapping.Column;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
import com.datastax.driver.core.utils.UUIDs;
@Table(value = "memobox")
public class MemoBox {
@PrimaryKeyColumn(name = "id",ordinal = 1,type = PrimaryKeyType.PARTITIONED)
private UUID id = UUIDs.timeBased();
@Column(value = "name")
private String name;
@Column(value = "memo")
private String memo;
@Column(value = "date")
private Date date;
■实体:部门
package com.example.cassandra.entity;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.data.cassandra.mapping.Column;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
@Table(value="departments")
public class Departments {
@PrimaryKeyColumn(name = "department_id",ordinal = 1,type = PrimaryKeyType.PARTITIONED)
private int department_id;
@Column(value = "department_name")
private String department_name;
public Departments(int department_id,String department_name){
this.department_id = department_id;
this.department_name = department_name;
}
@OneToMany(fetch=FetchType.EAGER)
@JoinColumn(name="department_id",insertable=false,updatable=false)
private List<Employees> emp = new ArrayList<Employees>();
答案 0 :(得分:0)
您的Department
构造函数遇到了问题。删除Department
构造函数。