I'm looking how to map in JPA a hashmap with its value being a list.
I've 2 entities:
EntityA {
@Id
@GeneratedValue
private Integer id;
@MapKey(name = "nature")
@MapKeyEnumerated(EnumType.STRING)
@OneToMany(mappedBy = "entityA", cascade = CascadeType.ALL)
private Map<NatureEnum, List<EntityB>> mapEntityB = new HashMap<NatureEnum, List<EntityB>>();
}
EntityB {
@Id
@GeneratedValue
private Integer id;
@ManyToOne
@JoinColumn(name = "ID_ENTITYA", nullable = false)
private EntityA entityA;
@Column(name = "NATURE", nullable = false)
@Enumerated(EnumType.STRING)
private NatureEnum nature;
}
You will have guessed that of course the map doesn't work as it's missing something telling it it's not just one EntityB in it.
The rest does work and if i change the map by a regular List it works fine. So how can i manage to "group by" my EntityB in one list depending on the value of Nature?
Thanks in advance for your help.