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.  [ 2 posts ] 
Author Message
 Post subject: Need help converting SQL Query to HQL
PostPosted: Wed Mar 05, 2008 12:52 pm 
Newbie

Joined: Tue Jan 15, 2008 4:27 pm
Posts: 5
Hello everyone! I'm not new to Hibernate, but I am learning .Net. Could I get some pointers on how to convert this old SQL query into hql?

SELECT dbo.BillingAccount.BillingAccountId, dbo.Customer.CustomerName, dbo.BillingAccount.BillingAccountNumber,
(SELECT COUNT(*) AS Expr1
FROM dbo.Device
WHERE (BillingAccountId = dbo.BillingAccount.BillingAccountId)) AS DeviceCount, dbo.BillingAccount.Notes, dbo.BillingAccount.LastModified
FROM dbo.BillingAccount LEFT OUTER JOIN
dbo.AuthUser ON dbo.AuthUser.AuthUserId = dbo.BillingAccount.LastModifiedBy LEFT OUTER JOIN
dbo.Customer ON dbo.Customer.CustomerId = dbo.BillingAccount.CustomerId
WHERE (dbo.BillingAccount.Deactivated IS NULL)

I have two problems:

How do I sub-select within HQL (for the count(*)).

How do I join on non(domain) relational entities? ie: on the first join here, BillingAccount is not related to AuthUser, but the lastmodifiedby column is the ID of the AuthUser that last modified that entity.

Thanks in advance!!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 1:49 pm 
Newbie

Joined: Tue Jan 15, 2008 4:27 pm
Posts: 5
Ok, I found my answer for counting elements - here's my current query.

select BA.Id, C.CustomerName, BA.BillingAccountNumber, count(elements(BA.DeviceSet)) from BillingAccount BA left join BA.Customer C group by BA.Id, C.CustomerName, BA.BillingAccountNumber

The only thing I'm stuck on is how to join to a non-relational field

Any suggestions?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.