9.1.4. 混合使用“每个类分层结构一张表”和“每个子类一张表”

你甚至可以采取如下方法混和使用“每个类分层结构一张表”和“每个子类一张表”这两种策略:

  1. <class name="Payment" table="PAYMENT">
  2. <id name="id" type="long" column="PAYMENT_ID">
  3. <generator class="native"/>
  4. </id>
  5. <discriminator column="PAYMENT_TYPE" type="string"/>
  6. <property name="amount" column="AMOUNT"/>
  7. ...
  8. <subclass name="CreditCardPayment" discriminator-value="CREDIT">
  9. <join table="CREDIT_PAYMENT">
  10. <property name="creditCardType" column="CCTYPE"/>
  11. ...
  12. </join>
  13. </subclass>
  14. <subclass name="CashPayment" discriminator-value="CASH">
  15. ...
  16. </subclass>
  17. <subclass name="ChequePayment" discriminator-value="CHEQUE">
  18. ...
  19. </subclass>
  20. </class>

对上述任何一种映射策略而言,指向根类Payment的 关联是使用&lt;many-to-one&gt;进行映射的。

  1. <many-to-one name="payment" column="PAYMENT_ID" class="Payment"/>