That's a good idea.
<hibernate-mapping>
<class name="InventoryManager" table="inventory">
<id name="inventory_number" column="inventory_number">
<generator class="increment"/>
</id>
<map name="inventoryItems" table="inventory_item_map">
<key column="inventory_number"/>
<map-key-many-to-many column="item_number" class="Item"/>
<element type="integer" column="quantity"/>
</map>
<one-to-one name="owner" class="User"/>
</class>
</hibernate-mapping>
create table inventory(
inventory_number bigint,
user_number bigint,
primary key(inventory_number),
foreign key(user_number) references users(id)
);
create table inventory_item_map(
inventory_number bigint,
item_number bigint,
quantity int,
primary key(inventory_number,item_number),
foreign key(inventory_number) references inventory(inventory_number),
foreign key(item_number) references item(item_number)
);
Thanks.
|