I am trying to save an enumeration in Cassandra using the Springdata framework. Is it possible? I defined my enum:
public enum Currency {
GBP,
USD,
EUR
}
Then I define my class with @Enumerated annotation in 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;
...
This is my import:
import com.datastax.driver.mapping.EnumType;
import com.datastax.driver.mapping.annotations.Enumerated;
Then I have a Component class for Spring:
@Component
class CassandraDataCLR implements CommandLineRunner {
@Autowired
public BondStaticCassandraRepository bondStaticRepository;
...
Refuses to:
@RepositoryRestResource(path = "/bond-static")
interface BondStaticCassandraRepository extends CassandraRepository<BondStatic> {
}
Where is my import:
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? A simple solution is to make my fields in String and use the enumeration in getter and setter, but it seems like the annotated enum is a much cleaner solution if I can make it work.
source
share