• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HQL doubt.

 
manoj kumar jena
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to retrieve data from two tables using HQL without using join?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do this in a relation database. If you mention more than one table in a sql statement you are doing some sort of join, even if it is the most basic union.

So you can't do this in HQL without using a join either. You can make it appear you are not using a join by defining a non-lazy association between your tables in your mapping files (which still uses a join in the SQL it generates, you've just defined it differently).

You can also do what is known as implicit joining in HQL. This is when you use dot notation in your HQL, e.g. :

The join is implicit between foo and bar. This still results in an inner join being used though.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, one way might be to have one Java class map to two separate database tables. Then, when you do an HQL query on that one class, the query will actually span across two tables.

But then again, that's really all just smoke and mirrors. Under the covers, as it has been noted, there will be some sort of a join going on.

If it makes no sense to have the data bridged through a join, maybe the data shouldn't be in two separate tables at all. Maybe the answer is to redesign your database. Database Administrators are always thrilled to hear that.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic