Hibernate version: 3.3.1 GA, with Apache Derby Embedded 10.4.2.0
I started from the sample about inheritance in the book
Java Persistence with Hibernate, with a table per hierarchy mapping strategy (see Fig 5.2 on P.199).
I extended the example by adding a RemuneratedAccount class that extends BankAccount.
RemuneratedAccount has a unique property, rate of type float.
So the hierarchy looks like:
Code:
BillingDetails
|- CreditCard
|- BankAccount
|- RemuneratedAccount
The mapping provided is as follows:
Code:
<hibernate-mapping>
<class name="testcase.BillingDetails" table="BILLING_DETAILS" discriminator-value="BD">
<id name="id" column="BD_ID"/>
<discriminator column="DISC"/>
<property name="owner" column="BD_OWNER"/>
<subclass name="testcase.CreditCard" extends="testcase.BillingDetails" discriminator-value="CC">
<property name="number" column="CC_NUMBER"/>
<property name="expMonth" column="CC_EXPMONTH"/>
<property name="expYear" column="CC_EXPYEAR"/>
</subclass>
<subclass name="testcase.BankAccount" extends="testcase.BillingDetails" discriminator-value="BA">
<property name="account" column="BA_ACCOUNT"/>
<property name="bankName" column="BA_BANKNAME"/>
</subclass>
<subclass name="testcase.RemuneratedAccount" extends="testcase.BankAccount" discriminator-value="RA">
<property name="rate" column="RA_RATE"/>
</subclass>
</class>
</hibernate-mapping>
Then, in the code of my application, I populate some instances of RemuneratedAccount and set a value for each property (id, owner, account, bankname, rate), including inherited ones, before saving and commiting them.
When I fetch my instances, the values for account and bankname (each one defined in BankAccount) are null. Every other property value is retrieved back with the right value.
When inserting, the generated JDBC statement is as follows:
insert into BILLING_DETAILS (BD_OWNER, RA_RATE, DISC, BD_ID) values (?, ?, 'RA', ?)
where we can see that columns BA_ACCOUNT and BA_BANKNAME are missing.
Did I do something wrong ? Can someone explain this strange behavior ?
Thanks in advance,
arnoth