Java Reference
In-Depth Information
Figure A-1. A problematic but legal schema
Here, the product table represents a product (for example, a flashlight). The color table
represents the colors in which it is sold. The link table named product_color then allows us to
identify a product by stock keeping unit (SKU), and identify the colors in which it is available.
If we do not mind the Product object retaining a set of colors (representing the colors in
which it can be sold), then we have no problem; but if we want to distinguish between a red
flashlight and a green one, things become more difficult (see Listing A-13).
Listing A-13. A Fairly Direct Representation of the Product
<class name="com.hibernatebook.legacy.Product" table="product_color">
<composite-id
class="com.hibernatebook.legacy.ProductKey"
name="key">
<key-property type="int" name="id" column="product_id"/>
<key-property type="int" name="colorId" column="color_id"/>
</composite-id>
<many-to-one
name="color"
class="com.hibernatebook.legacy.Color"
column="color_id"
insert="false"
update="false"/>
<many-to-one
name="data"
class="com.hibernatebook.legacy.ProductData"
column="product_id"
insert="false"
update="false"/>
</class>
Search WWH ::




Custom Search