I have the following entities:
@Entity
@Table(name = "TABLENAME")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="discriminator", discriminatorType=DiscriminatorType.STRING)
public class Base { ... }
@Entity
@DiscriminatorValue("value1")
public class SubEntity1 extends Base {}
@Entity
@DiscriminatorValue("value2")
public class SubEntity2 extends Base {}
I need to make a query without knowing the actual type of the result. Something like:
select b from Base b where b.discriminator=? and ...
I get this exception: Object with id: 31 was not of the specified subclass: packagename.Base
In this case the query result would contains only instances of the same sub-entity, but I have other queries where the result would be "mixed".
Is there any way to make a query like these?