Hi,
Is it possible with Hibernate3 to annotate table, inheritance and discriminator column in a MappedSuperclass (not an Entity)?
Example:
@MappedSuperclass
@Table(name="A_TABLE")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.INTEGER)
public abstract class A {
...
public abstract getType() {
...
}
...
}
@Entity
@DiscriminatorValue("1111")
public class B extends A {
}
@Entity
@DiscriminatorValue("2222")
public class C extends A {
}
This doesn't seem to work - as soon as you use the @MappedSuperclass annotation on the abstract base class, the annotations @Inheritance, @Table and @DiscriminatorColumn will be ignored.
The only workaround seems to be to make the base class an entity and assign it a bogus @DiscriminatorValue, e.g.
@Entity
@Table(name="A_TABLE")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorValue("0")
public abstract class A {
...
public abstract getType() {
...
}
...
}
The first example though seems more intuitive and the EJB3 spec is unclear about this (it only mentions that MappedSuperclass "cannot have a separate table"). Strictly spoken this looks like a bug/oversight. Anyone knows a workaround that would yield a similar result WITHOUT making the abstract base class an entity? TIA
|