2016-07-26 86 views
1

我有一個AbstractAccount hbm文件,其中我設置accountNumberprimarykey。我在我的Account.hbm.xml文件中擴展這個類,我想在這個主鍵上使用countryCodeaccountNumbercomposite 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> 

Account.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> 
+0

可以使用<加入子類>在Abstract.hbm.xml – Gokul

+0

@Gokul你能更具體,怎麼能我在這裏使用。無論如何,我無法改變繼承結構。 –

回答

0

Abstract.hbm.xml

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

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

    /* Account class properites */ 

    </join-subclass> 
</hibernate-mapping> 
+0

保持主鍵和某些常見屬性在兩個類 – Gokul

+0

中相同我無法更改Abstract.hbm.xml文件。它是大型項目的一部分,在項目中使用很多,也是由另一個團隊控制的項目。我想在'account hbm'中覆蓋它,這就是問題所在。謝謝回覆。 –