使用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" class="com.krmsoft.ais.project.vo.ProVersionId">
            <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>

文章出处
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值