I am trying to store an enum into Cassandra using the Springdata framework. Is this possible? I have defined my enum:
public enum Currency {
GBP,
USD,
EUR
}
Then I define my class with the "@Enumerated" annotation on the field:
@Table
public class BondStatic {
@PrimaryKey
private String id;
private String isin;
private String ticker;
private Date maturity;
private Double coupon;
@Enumerated(EnumType.STRING)
private Currency currency;
...
}
These are my imports:
import com.datastax.driver.mapping.EnumType;
import com.datastax.driver.mapping.annotations.Enumerated;
Then I have my Component class for Spring:
@Component
class CassandraDataCLR implements CommandLineRunner {
@Autowired
public BondStaticCassandraRepository bondStaticRepository;
...
}
Which is autowired from:
@RepositoryRestResource(path = "/bond-static")
interface BondStaticCassandraRepository extends CassandraRepository<BondStatic> { }
Where these are my imports:
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
But when I try to run the following:
bondStaticRepository.save(bondStatics);
I get:
Value 0 of type class pojo.PocEnums$Currency does not correspond to any CQL3 type
Any suggestions? The simple solution would be to make my fields into String and use the enum in the getter and setter, but it seems like having an annotated enum is a much cleaner solution if I can get it to work.