Hi. In my code I have inheritance structure as follows:
Code:
@Table(name = "TD_TASKS")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("")
@ForceDiscriminator
public abstract class TaskVO implements Serializable, Cloneable, EntityVO, TaskVOInterface {
@Id
@SequenceGenerator(name = "TD_TASKS_SEQ", sequenceName = "TD_TASKS_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TD_TASKS_SEQ")
protected Long id;
...
}
@Entity
@DiscriminatorValue("CyclicTaskVO")
@ForceDiscriminator
public class CyclicTaskVO extends TaskVO implements CyclicTaskVOInterface {
...
}
@Entity
@DiscriminatorValue("OrdinaryTaskVO")
@ForceDiscriminator
public class OrdinaryTaskVO extends TaskVO implements OrdinaryTaskVOInterface {
...
}
public interface EntityVO {
Long getId();
}
public interface TaskVOInterface extends EntityVO {
...
}
public interface CyclicTaskVOInterface extends TaskVOInterface {
...
}
public interface OrdinaryTaskVOInterface extends TaskVOInterface {
...
}
TaskDao uses generic Dao method :
Code:
public T get(long id) {
Class<T> modelDataClass = getModelDataClass();
Object model = getCurrentSession().get(modelDataClass, id);
return modelDataClass.cast(model);
}
in my case modelDataClass is set to taskVO, so the method works like :
return (TaskVO) getCurrentSession().get(TaskVO.class, id);
In some cases get method returns instances of CyclicTaskVO and OrdinaryTaskVO, but sometimes I get class that is
instance of proxy: TaskVO_$$_javassist_ 21. This instance cannot be cast to any of classes CyclicTaskVO or OrdinaryTaskVO.
I also cant cast it to OrdinaryTaskVOInterface or CyclicTaskVOInterface.
Why in some cases hibernate does not use DiscriminatorColumn value (which is set properly)? I get proxy to abstract class
which is useless for me.
Thanks for your help.