Переопределить первичный ключ в подклассе гибернации

У меня есть AbstractAccount HBM файл, где я установил accountNumber как primarykey, Я расширяю этот класс в моем Account.hbm.xml файл, где я хочу переместить этот первичный ключ как countryCode а также accountNumbercomposite 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>

1 ответ

Решение

Abstract.hbm.xml

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

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

    /* Account class properites */

     </join-subclass>
</hibernate-mapping>
Другие вопросы по тегам