I have a single table hierarchy shown below:
@MappedSuperclass
@Table(name = "v_contract_account", schema = "SAP")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@XmlRootElement
@XmlSeeAlso({CurrencyAccount.class, ProgramAccount.class})
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class AbstractContractAccount implements Serializable {
....
}
@Entity
@Table(name = "v_contract_account", schema = "SAP")
@Immutable
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue("0")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class CurrencyAccount extends AbstractContractAccount {
...
}
@Entity
@Table(name = "v_contract_account", schema = "SAP")
@Immutable
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue("1")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ProgramAccount extends AbstractContractAccount {
...
}
Right now it works as it is (except the discriminator stuff), but why is it that if I remove the table annotation from the subclass, Hibernate will throw an exception?
org.jboss.resteasy.spi.UnhandledException: java.lang.ClassCastException: org.jboss.resteasy.specimpl.BuiltResponse cannot be cast to [Lcom.zanox.internal.billingmasterdata.domain.entity.CurrencyAccount;
And the strange thing is, if I don't put the table and inheritance annotation in the abstract super class, everything still works fine. Does this mean MappedSuperClass doesn't care about the table and inheritance annotation? If the annotation @Inheritance(strategy = InheritanceType.SINGLE_TABLE) is not needed anywhere, then where do I specify it?
Btw, in my case here, Hibernate doesn't create the table, the table is there already and I just want to map it.