File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Murach's Java Servlets and JSP this week in the Servlets 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.

wood burning stoves
subject: HQL join problem
Similar Threads
LEFt OUTER JOIN returning extraneous results...
Complex HQL query conversion (from SQL)
So much on the Left Joins in Hibernate
Question on query - select one row with max value in one field
left join fetch returns duplicates