Hi,
I am interested in how I can create a map like the following:
Code:
private Map<Integer, String> sizeIdNameMap = new HashMap<Integer, String>();
where the integer belongs to the sizeId and the String is the name from the following Classes and DB design:
Code:
public class Product implements Comparable<Product>, Serializable {
private long id;
private long otherProductData;
private Map<Integer, String> sizeIdNameMap = new HashMap<Integer, String>();
//constructor;setters;getters;equals;hashCode
}
public class Size implements Comparable<Size>, Serializable {
private long id;
private long name;
//constructor;setters;getters;equals;hashCode
}
<hibernate-mapping package="beans">
<class name="Size" table="Size">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" type="string" column="name" />
</class>
<class name="Product" table="Product">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="otherProductData" type="string" not-null="true" length="200"/>
<map name="sizeIdNameMap" table="ProductSizeJunction">
<key column="personId"/>
<map-key column="sizeId" type="integer" />
<many-to-many ???????>
???????
</many-to-many>
</map>
</class>
</hibernate-mapping>
The database design:
As you can see the many-to-many map mapping is missing. When I went through the reference, the examples with many to many association (and join/link tables) were limited to set mapping or mapping a map where the key and value from the map are columns of the join table, but I couldn't find an example where you can map columns from the table on the other side of the many to many association. As you can see, I need the value of the map to be the name column in the Size table. Unfortunately most of the books regarding Hibernate follow the reference examples (regarding map mapping with join tables).
If someone knows this, I would appreciate the help.
Kind Regards,
Despot