我试图让spring数据将我的枚举类型转换为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;
由于spring-data cassandra不支持它,因此可以在getters/ssetters中实现此逻辑。
@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();
}