Java JPA:如何映射以日期为键的地图
通常,您将日期映射为Java JPA:如何映射以日期为键的地图,java,date,jpa,map,persistence,Java,Date,Jpa,Map,Persistence,通常,您将日期映射为@Temporal(TemporalType.Date),将映射为@manytomy或@Lob 现在我正试图绘制一张地图。我尝试了@ManyToMany@Temporal(TemporalType.DATE),但似乎不起作用: Exception Description: The type [class java.util.Map] for the attribute [x] on the entity class [y] is not a valid type for a
@Temporal(TemporalType.Date)
,将映射为@manytomy
或@Lob
现在我正试图绘制一张地图。我尝试了@ManyToMany@Temporal(TemporalType.DATE)
,但似乎不起作用:
Exception Description: The type [class java.util.Map] for the attribute [x] on the entity class [y] is not a valid type for a temporal mapping.
所以我的问题是,如何映射包含日期的地图?您尝试过类似的方法吗
@OneToMany
@MapKeyTemporal(DATE)
protected java.util.Map<java.util.Date, Employee> employees;
@OneToMany
@MapKeyTemporal(日期)
受保护的java.util.Map员工;
谢谢@MapKeyTemporal
确实是我需要的。不过,我已经编辑了您的答案,因为由于使用了Float
作为值,所以需要@ElementCollection
。