我正在尝试让 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;
最佳答案
由于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();
}
关于java - spring-data-cassandra 无法转换枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33532985/