• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
 
Bartender
Posts: 19668
92
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: 59762
188
  • 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
Bartender
Posts: 19668
92
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: 3596
39
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Employee table.
employeeId
managerId <-- FK to Employee.employeeId
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!