This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

HQL Hibernate INNER JOIN SUBQuery  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some experience in SQL, but my knowledge in HQL is limited

Here is my SQL query


Note:The outer most query is to get didtinct results only.

And the DTO






  So far I was able to complete only the inner most query in above two ways, but I am kind of stuck there.

This one works >>
But this one doesnt >>

If possible I would like to go with the first approach, like pure HQL, but I really doubt if thats possible.

Any suggestion will be much helpful
 
Saloon Keeper
Posts: 20502
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, instead of using legacy Hibernate, I'd recommend using Hibernate JPA. It has the advantage of being part of the Java JEE standard (as a subset of the EJB3 specs).

What little I knew of legacy Hibernate I forgot long ago, but I think you're trying to brute-force SQL into an ORM environment. Certainly in the case of JPA's query language you'd never explicitly code the word "join" in the query.

The point of ORM frameworks, be they legacy Hibernate, JDO, JPA or whatever is to minimize the low-level query language coding required. For example, you don't code to pull fields, you code to pull a record, and the ORM framework then populates that record ("ORM Entity Object") with the field values automatically. Likewise you don't code a join clause, you establish a relationship (one/one, one/many, etc.) between entity objects and the ORM framework will then automatically do the join and fetch.
 
Marshal
Posts: 63345
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our Hibernate/ORM forum.
 
Koushik Paul
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Tim Holloway
I agree with you, but here all I am using for this particular query is one single table. So I am not sure how the mapping should be, if at all it will....
 
Tim Holloway
Saloon Keeper
Posts: 20502
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you're dealing with a join, so by definition, it's 2 tables. The fact that both "tables" (or more correctly, Entity instances) are the same Entity class type is immaterial.

Nothing in ORM architecture says that a table relationship has to be limited to other types of tables.
 
Koushik Paul
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is correct , but what will b the relation , how can some table can be a parent/child table of itself?
 
Rancher
Posts: 3921
45
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Employee table.
employeeId
managerId <-- FK to Employee.employeeId
 
a wee bit from the empire
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!