-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to refactor this native sql to HQL/JPAQL?
PostPosted: Thu Mar 12, 2009 5:22 pm 
This is a valid native query for MSSQL JDBC driver. How can I re-write this as HQL? thx.

Code:
select er.equipmentRepairId, e.serialNumber,
                   ddv.description,
                   sum(erc.cost) as Cost
                   from Equipment as e
                   inner join EquipmentRepair as er on er.equipmentId = e.equipmentId
                   left outer join EquipmentRepairCost as erc on er.equipmentRepairId = erc.equipmentRepairId
                   left outer join DropDownValue as ddv on er.equipmentRepairTypeCode = ddv.code
                   left outer join DropDown as dd on dd.listId = ddv.listId 
                   where e.serialNumber = :serialNumber and 
                   dd.listName = :repairTypeDropDown
                   group by er.equipmentRepairId,
                   e.serialNumber,
                   ddv.description


Top
  
 
 Post subject: Re: How to refactor this native sql to HQL/JPAQL?
PostPosted: Thu Mar 12, 2009 6:39 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
rabies wrote:
This is a valid native query for MSSQL JDBC driver. How can I re-write this as HQL? thx.

Code:
select er.equipmentRepairId, e.serialNumber,
                   ddv.description,
                   sum(erc.cost) as Cost
                   from Equipment as e
                   inner join EquipmentRepair as er on er.equipmentId = e.equipmentId
                   left outer join EquipmentRepairCost as erc on er.equipmentRepairId = erc.equipmentRepairId
                   left outer join DropDownValue as ddv on er.equipmentRepairTypeCode = ddv.code
                   left outer join DropDown as dd on dd.listId = ddv.listId 
                   where e.serialNumber = :serialNumber and 
                   dd.listName = :repairTypeDropDown
                   group by er.equipmentRepairId,
                   e.serialNumber,
                   ddv.description


Have you created the pojo files? Please post your java code first.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 6:51 pm 
after reading a couple other threads in this forum, it looks like it's not possible to do left joins in HQL if there is no mapping b/n the two entities (which is the case here).

We are going to stick with native query or stored proc for this case. thx.


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.