-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Polymorphic queries and table per hierarchy subclassing
PostPosted: Mon Apr 21, 2008 11:58 am 
Newbie

Joined: Mon Jan 21, 2008 7:30 am
Posts: 9
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.