CassandraInvalidQueryException字符串未验证复合主查询

时间:2016-11-14 17:46:30

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

我正在尝试将Spring-Data-Cassandra与UserDefinedType和Compound Query Key一起使用。我正在使用spring-cql和spring-data-cassandra的1.5.0.DATACASS-172-SNAPSHOT。代码抛出异常。

Caused by: org.springframework.cassandra.support.exception.CassandraInvalidQueryException: 
String didn't validate.; nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: 
String didn't validate.

以下是我的代码

@PrimaryKeyClass
public class EmployeeIdKey implements Serializable {
    @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED,name = "id")
    @CassandraType(type = DataType.Name.UUID)
    private UUID id;
    @PrimaryKeyColumn(ordinal = 1,type = PrimaryKeyType.CLUSTERED, name = "user_id")
    @CassandraType(type = DataType.Name.TEXT)
    private String userId;

    public EmployeeIdKey(){
        id = null;
        userId = null;
    }

    public UUID getUuId() {
        return id;
    }

    public void setUuId(UUID uuId) {
        this.id = uuId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }
}

Employee.java

@Table("employee")
public class Employee {
    @PrimaryKey
    private EmployeeIdKey id;

    private Person person;

    @Column("employee_no")
    private String employeeNo;

    @Column("email_ids")
    private List<String> emailId;
    //Getters and setters
}

Person.java

@UserDefinedType
public class Person {

    public Person(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;

    }
    @Column("first_name")
    private String firstName;
    @Column("last_name")
    private String lastName;
// Getters adn setters;
}

EmployeeRepository.java

public interface EmployeeRepository extends TypedIdCassandraRepository<Employee,EmployeeIdKey> {
}

App.java

@SpringBootApplication
public class App {

    public static void main(String[] args) {
        SpringApplication.run(App.class);
    }
    @Bean
    public CommandLineRunner demo( EmployeeRepository repository) {
        Employee employee = new Employee();
        EmployeeIdKey key = new EmployeeIdKey();
        key.setUserId("55550");
        key.setUuId(UUID.randomUUID());
        employee.setId(key);
        List<String> emailIds = Arrays.asList("myemail@domain.com","myemail2@domain2.com");
        employee.setEmailId(emailIds);
        Person person = new Person("John", "Mathew");
        employee.setPerson(person);


        repository.save(employee);
        return  null;
    }
}

当我使用简单的主键时,效果很好。

0 个答案:

没有答案