I am developing an application which deals with two following entities: Products (let\'s name it as X, Y, Z) and Materials (a, b, c, ...). It\'
Since nobody posted the solution without annotations, I'll show the solution with JPA 2.0 @ElementCollection
annotation:
@ElementCollection
@CollectionTable(name = "Recipes",
joinColumns = @JoinColumn(name = "product_id"))
@MapKeyJoinColumn(name = "material_id")
@Column(name = "count")
private Map<Material, Integer> recipe;
Also note that since class of values of your map is Integer
, solution without annotations is likely to be documented as "collection mapping" rather than "entity relationship mapping".