spring-data-cassandra icon indicating copy to clipboard operation
spring-data-cassandra copied to clipboard

Enumerated types cannot be queried or saved

Open whisper-bye opened this issue 2 years ago • 0 comments

It works for text data type, but numeric types do not work like int tinyint etc.

https://docs.spring.io/spring-data/cassandra/docs/current/reference/html/#mapping-conversion

Enum text (default), bigint, varint, int, smallint, tinyint
create table user
(
    user_id    uuid,
    first_name text,
    last_name  text,
    state      tinyint, // text
);

@Table(value = "user")
public class User {
  @Column(value = "user_id")
  private UUID userId;

  @Column(value = "first_name")
  private String firstName;

  @Column(value = "last_name")
  private String lastName;

  @Column(value = "state")
  @CassandraType(type = CassandraType.Name.TINYINT)
  private CassandraEntityStateEnum state;
}

public enum CassandraEntityStateEnum {
  DISABLED,
  UNASSIGNED,
  ENABLED;
}

// create index user_state on user (state);

// repo
// Optional<User> findByState(CassandraEntityStateEnum state);
Codec not found for requested operation: [TINYINT <-> java.lang.String]
com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [TINYINT <-> java.lang.String]
	at app//com.datastax.oss.driver.internal.core.type.codec.registry.CachingCodecRegistry.createCodec(CachingCodecRegistry.java:609)
	at app//com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry$1.load(DefaultCodecRegistry.java:95)
	at app//com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry$1.load(DefaultCodecRegistry.java:92)
	at app//com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
	at app//com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2276)
	at app//com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2154)
	at app//com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$Segment.get(LocalCache.java:2044)
	at app//com.datastax.oss.driver.shaded.guava.common.cache.LocalCache.get(LocalCache.java:3951)
	at app//com.datastax.oss.driver.shaded.guava.common.cache.LocalCache.getOrLoad(LocalCache.java:3973)
	at app//com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4957)
	at app//com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4963)
	at app//com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry.getCachedCodec(DefaultCodecRegistry.java:117)
	at app//com.datastax.oss.driver.internal.core.type.codec.registry.CachingCodecRegistry.codecFor(CachingCodecRegistry.java:258)
	at app//com.datastax.oss.driver.internal.core.data.ValuesHelper.encodePreparedValues(ValuesHelper.java:112)
	at app//com.datastax.oss.driver.internal.core.cql.DefaultPreparedStatement.boundStatementBuilder(DefaultPreparedStatement.java:187)
	at app//org.springframework.data.cassandra.core.PreparedStatementDelegate.bind(PreparedStatementDelegate.java:60)
	at app//org.springframework.data.cassandra.core.CassandraTemplate$PreparedStatementHandler.bindValues(CassandraTemplate.java:1099)
	at app//org.springframework.data.cassandra.core.cql.CqlTemplate.query(CqlTemplate.java:538)
	at app//org.springframework.data.cassandra.core.cql.CqlTemplate.query(CqlTemplate.java:568)
	at app//org.springframework.data.cassandra.core.CassandraTemplate.doQuery(CassandraTemplate.java:939)
	at app//org.springframework.data.cassandra.core.CassandraTemplate.select(CassandraTemplate.java:380)
	at app//org.springframework.data.cassandra.repository.query.CassandraQueryExecution$SingleEntityExecution.execute(CassandraQueryExecution.java:161)
	at app//org.springframework.data.cassandra.repository.query.CassandraQueryExecution$ResultProcessingExecution.execute(CassandraQueryExecution.java:258)
	at app//org.springframework.data.cassandra.repository.query.AbstractCassandraQuery.execute(AbstractCassandraQuery.java:105)
	at app//org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
	at app//org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
	at app//org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:159)
	at app//org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:138)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at app//org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at app//org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
	at app/jdk.proxy3/jdk.proxy3.$Proxy197.findTopByKey_BucketAndState(Unknown Source)
	at app//com.demo.user.UserTests.saveUser(UserTests.java:45)

whisper-bye avatar Apr 25 '22 22:04 whisper-bye