java - 如何将 LocalDate 作为 JSON 属性存储在带有 Hibernate JPA 的 postgres jsonb 列中?
问题描述
我在 postgres 表中有一个 jsonb 列。对应的 JPA 实体字段是具有 LocalDate 属性的 Java DTO。LocalDate 字段作为列表存储在 postgres 中。
JAVA实体:
@Entity
@Table(name = "my_entity")
public class MyEntity
{
@EmbeddedId
private EmbeddedId embeddedId;
@Type(type = "jsonb")
@Column(name = "jsonb_column", columnDefinition = "jsonb", nullable = false)
private JavaDto javaDto;
}
JavaDto.java:
@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class JavaDto
{
private LocalDate localDate;
private String type;
private String id;
}
my_table
postgres 表中的示例行:
id | 90
other_col | OTHER_COL_VAL
jsonb_column | {"id": "123-some-id", "type": "someType", "localDate": [2021, 10, 13]}
creation_time | 2020-11-02 15:44:42.134+05:30
last_modified_time | 2020-11-02 15:44:42.134+05:30
存储 localDate 的格式会产生问题,以使用 where 子句运行读取查询。任何帮助,将不胜感激。
我使用 Hibernate 作为 JPA 实现。
解决方案
推荐阅读
- php - php 内爆函数空数组不起作用
- ruby-on-rails - 如何在 dokku 中更新捆绑器版本?
- javascript - 仅当鼠标向下移动列表时激活':悬停'并在鼠标向上移动时移除
- mongodb - mongodb:聚合和 $lookup 与 ObjectId
- python - 我是 Python 新手,plotly.plotly 出错
- java - 插入记录时如何使用spring jdbctemplate batchupdate覆盖?
- winapi - 禁用 Aero Shake 并启用窗口停靠 + WinApi
- c++ - CRTP:如何推断要用作返回类型的成员类型?
- python - 有没有办法检查一行是否有值?
- php - 如何过滤json代码