1

我有一个AbstractAccounthbm 文件,我将其设置accountNumberprimarykey. 我在我的文件中扩展了这个类,Account.hbm.xml我想将这个主键覆盖为countryCodeand accountNumber composite key。我怎样才能做到这一点?

Abstract.hbm.xml 文件。

<?xml version="1.0"?>
<!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.*.*.*.AbstractAccount" 
    abstract="true" 
    table="ACCOUNT" 
    lazy="false">
        <id name="accountNumber" type="java.lang.String">
            <column name="ACCOUNT_NUMBER" length="16" />
            <generator class="assigned" />
        </id>
       <discriminator column="ACCOUNT_TYPE" type="string"/>
       ................
    </class>
</hibernate-mapping>

帐号.hbm.xml

    <property name="modifiedDate" type="java.util.Date">
        <column name="MODIFIED_DATE"/>
    </property>
    <property name="countryCode" type="java.lang.String">
        <column name="COUNTRY_CODE"/>            
    </property>
    ...............
</subclass>   

我尝试过如下添加复合键,但它不起作用。

<composite-id name="account_country">
<key-property name="countryCode" column="COUNTRY_CODE" />
<key-property name="accountNumber" column="ACCOUNT_NUMBER" />
</composite-id>
4

1 回答 1

0

摘要.hbm.xml

<hibernate-mapping>  
    /* Abstract class properites */

     <joined-subclass name="Account" table="tablename">

    /* Account class properites */

     </join-subclass>
</hibernate-mapping>
于 2016-07-26T09:18:20.173 回答