我有一个AbstractAccount
hbm文件,其中我设置accountNumber
为primarykey
。我在我的Account.hbm.xml
文件中扩展这个类,我想在这个主键上使用countryCode
和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>
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>
可以使用<加入子类>加入子类>在Abstract.hbm.xml – Gokul
@Gokul你能更具体,怎么能我在这里使用。无论如何,我无法改变继承结构。 –