hibernate笔记,复习到第八章之前,..
时间:2010-10-24 来源:vcycyv
从性能优化的角度看,已经看到的一些技巧包括:dynamic-update, mutable, 用bag instead of list or set.
7.2.3 Adding columns to join tables
两种策略:
1. Mapping the join table to an intermediate entity
<class name="CategorizedItem"
table="CATEGORY_ITEM"
mutable="false">
<composite-id name="id" class="CategorizedItem$Id">
<key-property name="categoryId"
access="field"
column="CATEGORY_ID"/>
<key-property name="itemId"
access="field"
column="ITEM_ID"/>
</composite-id>
<property name="dateAdded"
column="ADDED_ON"
type="timestamp"
not-null="true"/>
<property name="username"
column="ADDED_BY_USER"
type="string"
not-null="true"/>
<many-to-one name="category"
column="CATEGORY_ID"
not-null="true"
insert="false"
update="false"/>
<many-to-one name="item"
column="ITEM_ID"
not-null="true"
insert="false"
update="false"/>
</class>
insert and update are set to false. This is necessary because the
columns are mapped twice, once in the composite key (which is responsible for
insertion of the values) and again for the many-to-one associations.
2. Mapping the join table to a collection of components
<class name="Category" table="CATEGORY">
...
<set name="categorizedItems" table="CATEGORY_ITEM">
<key column="CATEGORY_ID"/>
<composite-element class="CategorizedItem">
<parent name="category"/>
<many-to-one name="item"
column="ITEM_ID"
not-null="true"
class="Item"/>
<property name="username" column="ADDED_BY_USER"/>
<property name="dateAdded" column="ADDED_ON"/>
</composite-element>
</set>
</class>