Let\'s say I have two tables, Books and Reviews. Reviews has a column, stars, that can have a value between 1 and 5. A Book can have many Reviews.
How would I select al
I don't think you can do what you want using a single query. You can certainly do it in two, however (using EJBQL with named parameters):
SELECT r FROM Reviews r WHERE r.book = :book ORDER BY r.stars ASC LIMIT 3;
SELECT r FROM Reviews r WHERE r.book = :book ORDER BY r.stars DESC LIMIT 3;
And you could of course write a simple helper method that makes both of these calls and collates the results into whatever data structure you prefer.