I have 2 subclasses, NetSettlement and GrossSettlement which are both derived from the superclass SettlementBase. A discriminator column is used to map to either the subclasses.
ie:
@MappedSuperclass
public abstract class SettlementBase
...
@Entity
@Table(name = "TIW_SETTLEMENT")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "MessageType", discriminatorType = DiscriminatorType.CHAR)
@DiscriminatorValue("N")
public class NetSettlement extends SettlementBase
...
@Entity
@Table(name = "TIW_SETTLEMENT")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "MessageType", discriminatorType = DiscriminatorType.CHAR)
@DiscriminatorValue("G")
public class GrossSettlement extends SettlementBase
...
I want to write a query which will return me instances of either NetSettlement or GrossSettlement, so I write a polymorphic query, eg
@NamedQuery(name="pending.settlements", query="from SettlementBase sb where sb.processingState = 'PENDING' ")
When I add this NamedQuery to my SettlementBase class and run a test to test the query, I get a hibernate.MappingException returned saying 'Named query not known'.
What am I doing wrong? I've read that polymorphic queries should be possible with the table per class hierarchy approach but can't find any examples anywhere.
|