If I understood you well, your Item is in fact a Product. So it means that a Product contain a one-to-many relationship to a set of productS, if only a Item-Product can only be part of ONLY ONE Product. In this case you only have to add an extra column inside Product telling wich Item-Product is is the child a a Parent-Product : "itemForeignKeyId" (pointing on ProductId).
In the other case, if an Item-Product can be part of many Products at the same time, you need to have a many-to-many relationship (and a database table item-product linking all Item-Product to a Product bu the ProductId key).
Lets check the simpler case:
You just have to create a Set (or any collection) of "items" in you Product class. This Set will be linked to a set of "itself"... Products.
in the java code:
Code:
Set item = new HashSet();
Inside the Product mapping xml add :
Code:
<set name="items">
<key>
<column name="productId" not-null="false" />
</key>
<one-to-many class="Product" />
</set>
You can also make the inverse relationship many-to-one inside Product to another Product.
Code:
<many-to-one name="ParentProduct" class="Product">
<column name="itemForeignKeyId" not-null="false" />
</many-to-one>
This seems to me the easiest way.
For some transparency, you could also make a class Items heriting of Product and adding the Set of Items, and the getter/setter associated to it.
I also see that you subCategory could also be a Category pointing to itself... you could do the same pattern there also.
Hope it helped.
Etienne
Montreal