Hibernate 3.1rc2, Annotations 3.1b6. I want to do something like this:
Code:
@Entity
@Table(name="funds")
@Inheritance(strategy=JOINED, discriminatorType=INTEGER)
public abstract class Fund {
int id;
int balance;
...
}
@Entity
@Inheritance(discriminatorValue="1")
public class CashFund extends Fund {
// no additional properties for this subclass
}
@EmbeddedSuperclass
public abstract class FundWithBillingAddress extends Fund {
@ManyToOne
@JoinColumn(name="billing_address_id")
BillingAddress billingAddress;
}
@Entity
@Inheritance(discriminatorValue="2")
@Table(name="funds_cc")
public class CreditCardFund extends FundWithBillingAddress {
String cardNumber;
...
}
That is, I have an abstract subclass of an entity that contains some properties that are common to a few different concrete grandchildren of the entity. Those properties are in the grandchildren's joined tables, not in the top-level entity's table.
I can do this using XML mapping files by declaring the billingAddress property in the CreditCardFund class's mapping; Hibernate doesn't seem to care that the property actually came from a superclass.
When I try to do it using annotations, I get "@EmbeddedSuperclass cannot be a subclass of @Entity". Why is that restriction there? This seems like a perfectly legitimate thing to want to do (and you can, just not with annotations!)
In
another thread on this forum, one of the Hibernate team said, "You don't need @EmbeddedSuperclass in the middle of the hierarchy, just use @Entity instead" but that doesn't apply here -- in this case there is no separate table for the middle class, it's just where I define common properties of the grandchild classes. I tried using @Entity and got an error from my database about the fund_with_billing_address table not existing.
Thanks!