HIBERNATE裡面怎麼繼承一對多的關係呢

jongh發表於2008-06-29
ARTICLE和ARTICLE_TYPE是一對多的關係,我把ARTICLE做成兩類分別用於列表(TArticle)和詳細(TArticleInfo),下面是配製檔案,findById返回TArticle的時候可以透過getArticleTypes得到類別列表,但用TArticleInfo就總是空,請問應該如何設定呢?

<hibernate-mapping>
<class name="dao.article.TArticle" table="t_article" catalog="test">
<id name="uid" type="integer">
<column name="uid" />
<generator class="increment"> </generator>
</id>
<property name="title" type="string">
<column name="title" length="200" not-null="true" />
</property>
<property name="image" type="string">
<column name="image" length="100" not-null="true" />
</property>
<property name="createDate" type="timestamp">
<column name="create_date" length="0" not-null="true" />
</property>
<property name="hits" type="integer">
<column name="hits" not-null="true" />
</property>

<set name="articleTypes" inverse="true" cascade="all" table="t_article_type">
<key>
<column name="article_id" />
</key>
<one-to-many class="dao.article.TArticleType" />
</set>
</class>

<class name="dao.article.TArticleInfo" table="t_article" polymorphism="explicit" catalog="test">
<id name="uid" type="integer">
<column name="uid" />
<generator class="increment"> </generator>
</id>
<property name="title" type="string">
<column name="title" length="200" not-null="true" />
</property>
<property name="image" type="string">
<column name="image" length="100" not-null="true" />
</property>
<property name="createDate" type="timestamp">
<column name="create_date" length="0" not-null="true" />
</property>
<property name="hits" type="integer">
<column name="hits" not-null="true" />
</property>

<property name="subTitle" type="string">
<column name="sub_title" length="100" not-null="true" />
</property>
<property name="brief" type="string">
<column name="brief" length="200" not-null="true" />
</property>
<property name="content" type="string">
<column name="content" length="65535" not-null="true" />
</property>

</class>

<class name="dao.article.TArticleType" table="t_article_type" catalog="test">
<id name="uid" type="integer">
<column name="uid" />
<generator class="increment"> </generator>
</id>
<property column="article_id" name="articleId" type="integer"/>
<property name="typeId" type="integer">
<column name="type_id" not-null="true" />
</property>
<property name="sort" type="integer">
<column name="sort" not-null="true" />
</property>

<many-to-one name="article" class="dao.article.TArticle" insert="false" update="false">
<column name="article_id" />
</many-to-one>
</class>

</hibernate-mapping>

相關文章