Forums Register Login

JPA / JPQL : Order by Subclass

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2729 times.
Similar Threads
[JPA/TOPLINK] is the function "lower" supported in "order by" clause? if not, how....
JPA, JPQL and the lack of certain features.
Question on JPQL...
jpql, join on?
Basic understanding of JPQL and HQL
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:51:41.