• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA / JPQL : Order by Subclass

 
Sebastian Himberger
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i have a question regarding JPA and "Order By". I have the following class hierarchy:

- BaseAccount
|
|-> CustomerAccount
|-> BusinessAccount

The inheritance strategy is JOINED. I want to retrieve a list of BaseAccount's ordered by their subclass. E.g. first all BusinessAccounts and then all CustomerAccounts. Is there a way to formulate this in JPQL? This is the first time i have this requirement and googling for "JPA order by subclass" revealed nothing.

Has anybody an idea how to achieve this? I'm using Hibernate Entity Manager but would preferr to solve this using pure JPA.

My first idea was to use a discriminator column but this hasn't worked so far.

Thanks very much in advance.

best regards,
Sebastian
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know exactly, but I would approach it like this: since "order by"
needs a property, I would define a property with a get method that returns the class name, or the table name.
[ December 05, 2007: Message edited by: Edvins Reisons ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic