7

目前我有这样的结构:

A
|
+--B
|
+--C

它使用连接表映射到每个子类一个表。由于历史原因,我也使用了鉴别器,因此目前的情况如Hibernate 手册第 9.1.3 节所述

问题:如何扩展这样的结构的映射:

A
|
+--B
|  |
|  D
|
+--C

我可以<subclass><subclass>休眠映射中吗?我需要什么<key>

4

2 回答 2

6

未经测试,但根据您发布的链接,如果您使用的是 hibernate3

<hibernate-mapping>
  <class name="A" table="A">
    <id name="id" type="long" column="a_id">
      <generator class="native"/>
    </id>
    <discriminator column="discriminator_col" type="string"/>
    <property name="" type=""/>
    <!-- ... -->
  </class>
  <subclass name="B" extends="A" discriminator-value="B">
    <!-- ... -->
  </subclass>
  <subclass name="D" extends="B" discriminator-value="D">
    <!-- ... -->
  </subclass>
  <subclass name="C" extends="A" discriminator-value="C">
    <!-- ... -->
  </subclass>
</hibernate-mapping>
于 2008-11-04T17:41:52.233 回答
0

使用 Annotations 可以做到以下几点:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name="LoanType",discriminatorType="String")
@Table(name = "A")
public class A implements Serializable{
}

@Entity
@Table(name= "B")
@PrimaryKeyJoinColumn(name = "B_ID", referencedColumnName ="A_ID")
public class B extends A{
}


@Entity
@Table(name= "C")
@PrimaryKeyJoinColumn(name = "C_ID", referencedColumnName = "B_ID")
public class C extends B{}
于 2017-12-13T12:04:22.190 回答