文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>hibernate笔记,复习到第八章之前,..

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>

相关阅读 更多 +
排行榜 更多 +
瓢虫少女

瓢虫少女

飞行射击 下载
潜艇鱼雷

潜艇鱼雷

飞行射击 下载
网络掠夺者

网络掠夺者

飞行射击 下载