I have entity hierarchy with inheriatnce type SINGLE_TABLE :
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("junioruser")
@DiscriminatorColumn(name = "dtype", discriminatorType = DiscriminatorType.STRING)
.........
public class JuniorUser {
The problem is how to map this JuniorUser entity and all its subclasses as property in Answer entity as :
@Entity
public class Answer {
private JuniorUser user;
..........................
If it is not possible then how can I map to 'user' property in Answer entity correct subclass of JuniorUser or JuniorUser itself using hibernate 4?
UPDATE: I do this to retrieve Answer and associated user:
Answer answer = sessionFactory.getCurrentSession().get(entityClass, id);
Asking for canonical name of related user
answer.getUser().getClass().getCanonicalName();
gives com.javahelp.domain.impl.JuniorUser_$$_javassist_3
Next asking for value of property dtype it gives 'junioruser'.
The final thing is that all other properties of this user are null including user_id property.
I myself see that for retrieved answer I have related user which has dtype as 'expertuser'
Thank you!