-->
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: complex query and filter
PostPosted: Sat Oct 08, 2005 5:54 pm 
Newbie

Joined: Thu Jan 20, 2005 12:05 pm
Posts: 2
Hello,

I’m using Hibernate 3, with Oracle. I’m working on a query, and wish to apply it as a filter. The actual system and tables are much more complex, so I came up with a simpler scenario to illustrate our core problem. The nature of the query should be exactly the same as this:

TABLE:
======
Let’s say I have a table empHours, with columns: empId, month, hours. It records how many hours each employee worked for each month this year. I have an object mapping to this table.

QUERY:
=======
We want to find out: “For each month, find the employee with the max #hours who worked less than 40 hours.” The 40 hours would the query pararmeter.

SQL:
===
Here’s the SQL I was able to come up with. Notice the join between e1 and e2.

SELECT e1.*
FROM empHours e1,
(SELECT month, max(hours) as maxHours
FROM empHours
WHERE hours < :hour_param
GROUP BY month) e2
WHERE e1.month = e2.month
AND e1.hours = e2.maxHours;

MY QUESTION:
============
1. Can this be translated into HQL? Notice e2 itself is not a real table, or a real object.
2. Is this something we can fit in a filter? How?

I will be happy if the sql can be somehow simplified, making it easier to fit into a filter.
(In the real world, we need to apply this condition to about 50 different tables.)


Thank you!


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.