java - 在 JPA 实体中返回并保留 LinkedHashMap 而不是 Map
问题描述
我试图LinkedHashMap
在我的 Spring Boot 项目中坚持我的 JPA 实体。我需要这个,因为与其他接口实现LinkedHashMap
相比,保留了插入顺序。Map
在我的Comic
JPA 实体中,我有以下字段:
@ElementCollection
@Column(name="price_history", nullable=true)
private Map<String, Float> priceHistory = new LinkedHashMap<String, Float>();
我的Comic
实体构造函数LinkedHashMap<String,Float>
也将 a 作为参数。
我的 getter 和 setter 方法如下所示:
public Map<String,Float> getPriceHistory() {
return priceHistory;
}
public void setPriceHistory(Map<String,Float> priceHistory) {
this.priceHistory = priceHistory;
}
我的 REST 控制器中有一个方法,允许我编辑任何Comic
JPA 实体实例的数据。以下代码负责将价格放入priceHistory
Map<String,Float>
对象中:
editComic.getPriceHistory().put(WordUtils.capitalizeFully(LocalDate.now().getMonth().toString()
+ " " + LocalDate.now().getYear()), price);
editComic.setPriceHistory(editComic.getPriceHistory());
有没有办法让我坚持LinkedHashMap<String,Float>
JPA?我尝试使用注释该字段,@Lob
但它在 PostgreSQL 中导致异常:
org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.
解决方案
推荐阅读
- python - waitress-serve --call 'helloweb:app' 给出模块异常
- html - Canvas 将其他 flexbox 项推送到容器外
- php - 使用 MPDF + OB_start() 导出列表 CRUD
- c# - C# 日期格式字符串使用 windows 设置而不是传递给它的字符串
- c# - 如何在 Unity 的 C# 中获取服务器端事件(onmessage)?
- wpf - .Net Core 3.1 WPF 中的 Prism 库
- rdf - 使用两种不同的@types 压缩 JSON-LD 属性?
- git - 如何从 Visual Studio 2019 中的提交中删除标记?
- python - 如何使用 Python 检查 2D 点是在 2D 闭合贝塞尔曲线内部还是外部?
- maven - 为 Jenkins 项目使用 Kubernetes 插件而不是管道