读书人

Hibernate对象照射关系。多态

发布时间: 2012-08-02 11:35:25 作者: rapoo

Hibernate对象映射关系。多态

?

3种策略?

hibernate中解决映射对象存在多态关系是一般使用3种策略。??

?共享同一个表

在该策略下,父类和子类数据都在一个表中。假设有3个类Container、Box、Bottle。其中Container<-Box,Container<-Bottle。对于这种策略,一般是使用discriminator。

?

?

?

<hibernate-mapping>    <class name="Container">        <id name="containerId">            <generator type="string"/>        <property name="size"/>        <property name="name"/>        <subclass name="Box" discriminator-value="BOX">            <property name="height"/>            <property name="length"/>            <property name="width"/>        </subclass>        <subclass name="Bottle" discriminator-value="BOTTLE">             <property name="diameter"/>             <property name="height"/>         </subclass>    </class></hibernate-mapping>

?

?

?

 

读书人网 >其他数据库

热点推荐