7

Currently I have a structure like this:

A
|
+--B
|
+--C

It's mapped with one table per subclass using joined tables. For historic reasons I also use a discriminator, so the current situation is as described in Section 9.1.3 of the Hibernate manual.

Question: How do I extend the mapping for a structure like this:

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

Can I <subclass> a <subclass> in the hibernate mapping? What <key>s do I need?

2 Answers 2

6

not tested but, according to the link you posted if you are using 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>
Sign up to request clarification or add additional context in comments.

Comments

0

Using Annotations, it can be done as follows:

@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{}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.