SQL to HQL translation problem

  • Thread starter Jakub =?UTF-8?B?S3XFum1h?=
  • Start date
J

Jakub =?UTF-8?B?S3XFum1h?=

Hello,

I am newbie in Java and Hibernate. I need to translate the following
SQL query:

select t.*, v.capacity - sum(d.weight) as capacity
from transits t
join deliveries d on t.id = d.transitid
join vehicles v on t.vehicleid = v.id
group by t.id
having capacity >= :capacityMin

.... to Hibernate Query Language. I've tried with:

select t, v.capacity - sum(d.weight) as capacity
from Transit t
join t.deliveries d
join t.vehicle v
group by t.id
having capacity >= :capacityMin

But it doesn't work (no such column 'capacity'). Is there any other way
to do that?

Greetings and TIA.
 
L

Lew

Jakub said:
Hello,

I am newbie in Java and Hibernate. I need to translate the following
SQL query:

select t.*, v.capacity - sum(d.weight) as capacity
from transits t
join deliveries d on t.id = d.transitid
join vehicles v on t.vehicleid = v.id
group by t.id
having capacity >= :capacityMin

This is problematic SQL, because you are SELECTing t.* but GROUPing on t.id.
You have to use aggregate methods on all the columns that are not t.id.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top