Hi Dev's
I am doing my first steps with HibernateAnnotations (cool!).
I have an abstract class wherefrom two other classes are extending.
Both these classes I want to persist in one table, doing the
discrimination by 'defining a formula' (a field existing only
in one of the subclasses, lets say UserTypeB):
In short something like:
@MappedSuperclass
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorFormula("case when type is null then 'A' else 'B' end")
public abstract class AbstractUser implements Serializable, Comparable {
...
}
@Entity
@Table (name="`GEOENTRY`")
@DiscriminatorValue("A")
public class UserTypeA extends AbstractUser {
...
}
@Entity
@Table (name="`GEOENTRY`")
@DiscriminatorValue("B")
public class UserTypeB extends AbstractUser {
...
}
So far everyting looks nice. I can persist objects into the database.
However, if I search for all existing objects stored, I get a collection twice the size of existing rows. Concretely, I get for every row an instantiated
object of UserTypeA and UserTypeB, each.
I am very sure that I am simply doing something wrong with using the Annotations.
Can someone point out what I am doing wrong?
Is there some other recommendation to implement this?
Some other source of good examples (besides the Annotation documentation)
Thanks for any beginner's help!
Environment:
- Hibernate 3.2.0.ga
- HibernateAnnotations 3.2.0.ga
- Database: Postgres 8.1
- Using Session and Transaction handling provided by HibernateTemplate of the Springframework
|