I'm trying to persist a LinkedHashMap
in my JPA Entity in a Spring Boot project of mine. I need this due to LinkedHashMap
preserving insertion-order compared to other Map
interface implementations.
In my Comic
JPA Entity, I have the field:
@ElementCollection
@Column(name="price_history", nullable=true)
private Map<String, Float> priceHistory = new LinkedHashMap<String, Float>();
My constructor for the Comic
entity takes a LinkedHashMap<String,Float>
as a parameter as well.
My getter and setter methods look like this:
public Map<String,Float> getPriceHistory() {
return priceHistory;
}
public void setPriceHistory(Map<String,Float> priceHistory) {
this.priceHistory = priceHistory;
}
I have a method in my REST controller that allows me to edit the data for any Comic
JPA entity instance. The following piece of code takes care of putting prices into the priceHistory
Map<String,Float>
object:
editComic.getPriceHistory().put(WordUtils.capitalizeFully(LocalDate.now().getMonth().toString()
+ " " + LocalDate.now().getYear()), price);
editComic.setPriceHistory(editComic.getPriceHistory());
Is there a way for me to persist LinkedHashMap<String,Float>
in JPA? I've tried annotating the field with @Lob
but it causes an exception in PostgreSQL:
org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…