Spring Cassandra存储带有自定义对象的列表

丹尼尔·艾森赖希(Daniel Eisenreich):

我喜欢存储如下对象:

@Table(value = "my_table")
public class MyTableDto {
  @PrimaryKeyColumn(name = "uid", type = PrimaryKeyType.PARTITIONED)
  @CassandraType(type = DataType.Name.UUID)
  private UUID uid;

  @Column(value = "child_ids")
  private List<ChildIdDto> childIds;
}

然后我得到异常:

Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Only primitive types are allowed inside Collections for property [childIds] of type ['interface java.util.List'] in entity [de.myapplication.repository.dto.MyTableDto]

我确实了解异常,但是还有另一种持久化自定义对象的方法吗?

编辑:

  • 当我注释掉此属性时,一切正常
丹尼尔·艾森赖希(Daniel Eisenreich):

永不言败,我找到了解决方案。

举一个很好的例子,我将列出所有相应的类。

ParentClass.java

@Table(value = "my_table") //OPT
public class MyTableDto {
  @PrimaryKeyColumn(name = "uid", type = PrimaryKeyType.PARTITIONED) 
  @CassandraType(type = DataType.Name.UUID)
  private UUID uid;

  @Column(value = "child_ids") //OPT
  private List<ChildDto> childIds;
}

ChildDto.java

@UserDefinedType // THE SOLUTION
public class ChildDto {
  @Column(value = "child") //OPT
  @CassandraType(type = DataType.Name.TEXT) //OPT
  private String groupId;

  @Column(value = "description") //OPT
  @CassandraType(type = Name.TEXT) //OPT
  private String description;
}

@UserDefinedType是解决方案。
有关更多信息,请参见此处

注意:不需要带有“ OPT”的每个注释

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Spring Boot从自定义查询中返回带有几个字段的自定义列表?

具有对象继承的存储库中的Spring Data自定义查询

使用自定义请求对象时带有可选参数的Spring @RequestMapping

Spring RestTemplate到带有自定义标头和请求对象的POST请求

编写带有参数的自定义spring注释?

带有自定义 fork 加入池的 Spring Boot

带有自定义UserDetailsService的Spring Boot

Spring Data - 带有自定义查询 (HQL) 的 PagingAndSortingRepository?

Spring @RequestBody没有映射到自定义对象

Spring安全性和带有Spring Boot的自定义AuthenticationFilter

带有spring-boot的spring-security,自定义登录页面,错误403

如何为Spring Data Cassandra创建自定义转换?

spring data cassandra react-自定义删除方法

仓库的自定义实现Spring-Data-Cassandra

使用 Spring Boot 中的自定义“根键”映射来自 application.yml 的对象列表

具有分页功能的Spring Data JPA自定义存储库

带有自定义 ReactiveAuthenticationManager 的 Spring Boot 执行器审计事件

带有自定义登录表单的 Spring Security 不起作用

带有自定义FieldSetMapper的Spring Batch是否不保存数据?

带有Spring Boot Webflux的自定义转换器未调用

带有Spring Web套接字和STOMP的自定义Jetty WebSocketPolicy

Spring 集成:带有标题丰富的自定义拆分器

带有自定义提供程序的 Spring Boot + Security OAuth2.0 客户端

如何使用带有共享字段的Spring Data JPA创建自定义查询?

如何使用Spring的WebClient发送带有自定义标头的删除请求?

在类级别带有RequestMapping注释的Spring Boot Actuator自定义RestControllerEndpoint

带有自定义缓存管理器实现的Spring Cache抽象无法正常工作

Gradle:用于Spring Boot的带有jvm参数的自定义任务

在Spring MVC项目中使用带有自定义消息转换器的springdoc