This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes HQL join problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HQL join problem" Watch "HQL join problem" New topic

HQL join problem

Prasath Premkumar
Ranch Hand

Joined: Nov 13, 2008
Posts: 43

Hi all,

I have a table named doc_type and another one named release. In doc_type.hbm.xml i have defined a many-to-one mapping for release like this:

note that DocType can be without release too.

I wrote a HQL like this for a scenario where i needed to get all the doctypes (with or without release) for a common name ordered by release.releaseOrder and issueDate.

But it didnt return DocTypes which dont have release. But when i removed from the order by clause, it returned all the doctypes with or without release object. (which is the expected behavior). So i found out that since i'm using an attribute of the Release object in HQL, when Release is null in DocType, it is not returning that record.

So i thought i can to a left join and wrote a HQL like this:

which returned everything but instead of returning a List, it resulted in List<List> something like that....

What is the possible HQL for this scenario???

Thanks in advance.
Prasath Premkumar
Ranch Hand

Joined: Nov 13, 2008
Posts: 43

I was able to fix that issue. Thanks anyway.

If anyone wants to know what i did:

This HQL does what i needed.

jQuery in Action, 3rd edition
subject: HQL join problem
It's not a secret anymore!