猿问

Spring Data Cassandra:InvalidQueryException:UUID

实体


@Builder

@Getter @Setter

@ToString(doNotUseGetters = true)

@EqualsAndHashCode(doNotUseGetters = true)

@Table(value = "entity")

public class Entity implements Serializable {


    @PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)

    @CassandraType(type = DataType.Name.UUID)

    private UUID Id;


    @Column("list_name")

    @CassandraType(type = DataType.Name.TEXT)

    private String name;


    @Column("type")

    @CassandraType(type = DataType.Name.TINYINT)

    private Byte type;

实体回购


@Repository

public interface EntityRepo extends BaseRepo<Entity, UUID> {


    @Query("SELECT * FROM entity WHERE id IN (:id)")

    Collection<ListEntity> findByIds(@Param("id") Collection<UUID> listIds);


    @Query("SELECT * FROM entity WHERE list_id = :id")

    ListEntity findById(@Param("id") UUID id);


}  

询问


listRepo.findByListId(UUIDs.random())

listRepo.findByListIds(Arrays.asList(UUIDs.random())

两者都导致


CassandraInvalidQueryException/InvalidQueryException

org.springframework.data.cassandra.CassandraInvalidQueryException: Query; CQL 

[SELECT * FROM lists WHERE list_id IN (?)]; UUID should be 16 or 0 bytes (20); 

nested exception is com.datastax.driver.core.exceptions.`InvalidQueryException: UUID should be 16 or 0 bytes (20)

这里缺少什么吗?有人可以帮忙吗?


蛊毒传说
浏览 274回答 3
3回答

Cats萌萌

运行Spark应用程序时出现相同的错误。执行Cassandra查询时出现错误,并且在预期为UUID类型的地方,该查询发送了一些其他数据类型。就我而言,它是一个字符串。传递正确的数据类型(UUID代替String)解决了该问题。
随时随地看视频慕课网APP

相关分类

Java
我要回答