我有一个如下所示的表层次结构:
@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 {
...
}
现在它按原样工作(除了鉴别器的东西),但为什么如果我从子类中删除表注释,Hibernate 会抛出异常?
org.jboss.resteasy.spi.UnhandledException: java.lang.ClassCastException: org.jboss.resteasy.specimpl.BuiltResponse cannot be cast to [Lcom.zanox.internal.billingmasterdata.domain.entity.CurrencyAccount;
而且奇怪的是,如果我不把表和继承注解放在抽象超类中,一切照样正常。这是否意味着 MappedSuperClass 不关心表和继承注释?如果注释 @Inheritance(strategy = InheritanceType.SINGLE_TABLE) 在任何地方都不需要,那么我在哪里指定它?
顺便说一句,在我这里,Hibernate 不会创建表,表已经存在,我只想映射它。