spring-data-cassandra无法转换枚举

时间:2015-11-04 22:07:04

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

我正在尝试使用spring-data将我的枚举类型转换为cassandra中的int字段,但是我得到以下异常:

Unexpected runtime exception java.lang.IllegalArgumentException: 
Value 2 of type class com.twc.atg.td.dbo.client.ClassCode does not correspond to any CQL3 type   

以下是我正在使用的代码:

@Enumerated(EnumType.ORDINAL)
@Column("class_code")
public ClassCode classCode;

1 个答案:

答案 0 :(得分:1)

由于 spring-data-cassandra 不支持,您可以在getters / setters中实现此逻辑。

@Table
public class Writer {
    ...
    public enum WriterType {
        POET, DETECTIVE, JOUNALIST
    }

    ...
    @Column(value = "writer_type")
    private Integer writerType;

    ...
    public WriterType getWriterType() {
        return WriterType.values()[writerType];
    }

    public void setWriterType(WriterType writerType) {
        this.writerType = writerType.ordinal();
    }