java - org.postgresql.util.PSQLException:错误:列“check_state”的类型为 check_state,但表达式的类型为字符变化
问题描述
我在我的项目中使用 Spring Data JDBC,但我无法持久化具有与我的数据库中的 Postgres 枚举对应的枚举属性的对象。
我有一个与此类似的 PutMapping:
@PutMapping(value = "/{buildingId}/rooms/{roomId}")
public Room updateRoom(@PathVariable Long buildingId, @PathVariable Long roomId,
@RequestBody Set<Quad> quads) {
Optional<Room> toUpdate = roomRepo.findById(roomId);
if (toUpdate.isPresent()) {
Room room = toUpdate.get();
room.setQuads(quads);
roomRepo.save(room);
return room;
} else {
...
}
}
使用与此类似的 Quad 实体:
@Data
@Entity
@Table(value = "quads")
public class Quad {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long roomId;
private String quadLabel;
private CheckState checkState;
public Quad() {
checkState = CheckState.UNCHECKED;
}
}
使用相应的 CheckState 枚举:
public enum CheckState {
UNCHECKED,
CHECKED_DAMAGED,
CHECKED_INTACT,
RECHECK_NEEDED,
}
但是,当我尝试使用以下正文向此端点发送 PUT 请求时:
{
...
"checkState": "UNCHECKED",
...
}
我收到以下错误:
org.postgresql.util.PSQLException: ERROR: column "check_state" is of type check_state but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
我试图发送的 PUT 映射的主体似乎没有正确映射到正确的 Postgres 枚举,但我似乎无法弄清楚如何重写或转换表达式,就像使用 Repo.save 的提示所说的那样() 方法。
解决方案
推荐阅读
- r - R中的分组和数据透视表
- java - ElasticSearch 使字段不可从 java 中搜索
- javascript - 如何从复选框列表中返回所有选中和未选中的值?
- ruby-on-rails - Rails 中的 ActionDispatch::Cookies::CookieOverflow
- node.js - 导出的 Docker 镜像 tar 在提取和重新创建后不完全相同
- docker-compose - Apache Druid 无法连接到 zookeeper,Apache Druid 作为 docker 镜像部署在一个容器中
- r - 解析采访文本
- css - Conseguir que el thead de la tabla se quede stycky
- c# - C# UWP 发送列表到下一页
- uitextview - SwiftUI UITextView 包装器如何调整其内容以匹配父级