-->
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: how to handle a named query with CASE and UNION
PostPosted: Thu Mar 13, 2008 5:09 am 
Newbie

Joined: Mon Mar 05, 2007 4:38 am
Posts: 17
Hi all,

using the latest version of Hibernate, I am not sure how to handle this query:

select
TaskResources.PlanStartDate,
TaskResources.PlanEndDate,
TaskResources.PlanHours,
TaskResources.Resource as Role,
TaskResources.PlanResource as Person,
case when Tasks.TaskName like 'Budget%' then Projects.Title else Tasks.TaskName end Task,
case when Tasks.TaskName like 'Budget%' then Projects.Status else Tasks.Status end Status,
Projects.ProjectNumber,
Projects.Title,
Projects.Release,
Projects.Company,
Tasks.Assigned as 'Assigned Now',
Tasks.DocumentIdentifier
FROM Projects, Tasks, TaskResources
WHERE Tasks.ProjectNumber = Projects.ProjectNumber
AND TaskResources.TaskID = Tasks.TaskID
AND (Projects.Release like '%RELEASEARGUMENT%')
AND (Projects.Department='Sofico')
AND (TaskResources.PlanResource like '%PERSONARGUMENT%')
AND (TaskResources.PlanHours > 0)
AND (TaskResources.PlanResource <> '')
AND (TaskResources.PlanEndDate > getdate() - '%STARTDATEARGUMENT%')
AND (TaskResources.PlanStartDate <= getdate()+ '%ENDDATEARGUMENT%')
union
select VacationRequest.StartDate as PlanStartDate,
VacationRequest.EndDate as PlanEndDate,
Days*7.5 as PlanHours,
'*Vacation' as Role,
Users.LFName as Person,
'Officieel verlof 2008' as Name,
'Ongoing' as Status,
'02008' as ProjectNumber,
'Absence' as Title,
'' as Release,
'Sofico' as Company,
Users.LFName as 'Assigned Now',
'' DocumentIdentifier
from VacationRequest, Users
where VacationRequest."User" = Users.UserName
and (Users.Department = 'Sofico')
and (Users.LFName like '%PERSONARGUMENT%')
and (VacationRequest.Status = 'Approved')
and (VacationRequest.EndDate > getdate()- '%STARTDATEARGUMENT%'))
and (VacationRequest.StartDate <= getdate()+ '%ENDDATEARGUMENT%'))
order by PlanStartDate,Person

As you can see, it has two CASE stamenents and a UNION.
I have to produce a list on a HTML page with the results but I am not sure how to do this in Hibernate.
Due to the "complexity", would it be a good solution to go for scalar results? What would be the alternatives?

Thank you,
Steven


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.