This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Joins in Hibernate

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi!!!

There's problem in Hibernate.

I have three tables as :

Department(Dno,Dname)
Employee(Eno,Dno,Salary)
Project(Pno,Dno) i.e Here Dno represents The Department that controls that project.

Now I Want Output as :
Dname,sum(Salary),count(Project)

i.e. Total Salary paid to each Department and total number of projects controlled by each department.

i.e. Group by dno in Employee for Sum(Salary) and Group by dno in Project for count(*)
Then Join both results with Department to get desired results.


In Sql we write the Query as :

SELECT d.dname, a.s, b.c
FROM Department d,
(SELECT dno, sum(salary) s FROM Employee GROUP BY dno) a,
(SELECT dno, count(*) c FROM Project GROUP BY dno) b
WHERE d.dno=a.dno and a.dno=b.dno


I get the correct result from the above query.

Now Problem is how to write the same query in Hibernate.

DOES HIBERNATE SUPPORTS SUBQUERY IN FROM CLAUSE AS USED IN ABOVE SQL.


In java we have three classes as :

Department(dno,dname)
Employee(eno,salary and Object of Department dept)
Project(pno and Object of Department dept)


In hibernate I have write a query as :

SELECT d.dname,a.s,b.c
FROM Department d, (SELECT e.dept.dname dn,sum(salary) s FROM Employee e group by dn) a,
(SELECT p.dept.dname dnm, count(*) s FROM Project p group by dnm) b
Where d.dname = a.dn and a.dn = b.dnm

But Hibernate gives error in From clause where "(" starts.
I think Hibernate does not support Subquery in From clause.

Individually Employee group by and Project group by is alright in Hibernate.

Help me to Solve above Problem

Bye!!!
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is the same as your other post.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!