HIBERNATE里面怎么继承一对多的关系呢

jongh
08-06-29 0 238

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>