首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Hibernate联结主键

2012-09-10 
Hibernate联合主键使用Hibernate配置联合主键的两种方式1.主键字段和非主键字段在同一个实体类中,Hibernat

Hibernate联合主键
使用Hibernate配置联合主键的两种方式
1.主键字段和非主键字段在同一个实体类中,Hibernate配置文件如下
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.krmsoft.ais.project.vo.ProVersion" table="PRO_VERSION">
        <comment>脱机版版本号</comment>
         <composite-id>
            <key-property name="verNo" type="java.lang.Integer">
                <column name="VER_NO" not-null="true">               
                <comment>版本号</comment>
                </column>
            </key-property>
            <key-property name="buildNo" type="java.lang.Integer">
                <column name="BUILD_NO" not-null="true">               
                <comment>升级号</comment>
                </column>
            </key-property>
        </composite-id>
        <property name="buildTime" type="java.lang.String">
            <column name="BUILD_TIME" length="32" not-null="true">
                <comment>升级日期</comment>
            </column>
        </property>
        <property name="verName" type="java.lang.String">
            <column name="VER_NAME">
                <comment>版本名称</comment>
            </column>
        </property>
        <property name="verDesc" type="java.lang.String">
            <column name="VER_DESC">
                <comment>版本描述</comment>
            </column>
        </property>
        <property name="creatorId" type="java.lang.String">
            <column name="CREATOR_ID" length="10" not-null="true">
                <comment>创建人</comment>
            </column>
        </property>
        <property name="createTime" type="java.lang.String">
            <column name="CREATE_TIME" length="20" not-null="true">
                <comment>创建时间</comment>
            </column>
        </property>
    </class>
</hibernate-mapping>

2.主键字段和非主键字段不在同一个实体类中,Hibernate配置文件如下
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.krmsoft.ais.project.vo.ProVersion" table="PRO_VERSION">
        <comment>脱机版版本号</comment>
         <composite-id  name="id" type="java.lang.Integer">
                <column name="VER_NO" not-null="true">               
                <comment>版本号</comment>
                </column>
            </key-property>
            <key-property name="buildNo" type="java.lang.Integer">
                <column name="BUILD_NO" not-null="true">               
                <comment>升级号</comment>
                </column>
            </key-property>
        </composite-id>
        <property name="buildTime" type="java.lang.String">
            <column name="BUILD_TIME" length="32" not-null="true">
                <comment>升级日期</comment>
            </column>
        </property>
        <property name="verName" type="java.lang.String">
            <column name="VER_NAME">
                <comment>版本名称</comment>
            </column>
        </property>
        <property name="verDesc" type="java.lang.String">
            <column name="VER_DESC">
                <comment>版本描述</comment>
            </column>
        </property>
        <property name="creatorId" type="java.lang.String">
            <column name="CREATOR_ID" length="10" not-null="true">
                <comment>创建人</comment>
            </column>
        </property>
        <property name="createTime" type="java.lang.String">
            <column name="CREATE_TIME" length="20" not-null="true">
                <comment>创建时间</comment>
            </column>
        </property>
    </class>
</hibernate-mapping>

热点排行