Search code examples
javadatejpadictionarypersistence

JPA: How to map a Map with Date as key


Normally you'd map a Date as @Temporal(TemporalType.DATE) and you'd map a Map<> as @ManyToMany or @Lob.

Now I am trying to map a Map. I have tried @ManyToMany @Temporal(TemporalType.DATE) but this doesn't seem to work:

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.

So my question is, how to map a Map containing a Date?


Solution

  • Have you tried something like this?

     @OneToMany
     @MapKeyTemporal(DATE)
     protected java.util.Map<java.util.Date, Employee> employees;