Hello all,
I'm using NHibernate, but my problem also occur in Hibernate, I think.
I've an object model like this (omitting getters and setters):
class ChangeRequest {
private long id; //PK
private string title;
private User responsible; //FK to User table
}
class User {
private long id; //PK
private string name;
}
The relational model is straightforward. Now, I'd like to write an HQL query to get only the ChangeRequest's title and it's responsible name.
The HQL would be like this:
session.CreateQuery("SELECT cr.title, cr.responsible.name FROM ChangeRequest as cr");
The data I have in my database is:
ChangeRequest table
-------------------
id title Responsible_ID
1 Error in Main Form 2
2 Exception raised in Login Form NULL
3 Concurrency issue in admin module NULL
User table
----------
id name
1 Sean
2 Julio
My problem is the following: I'd like to get the following result from this query:
cr.title cr.responsible.name
Error in Main Form Julio
Exception raised in Login Form NULL
Concurrency issue in admin module NULL
This way, I could show in the grid a report with the 3 CRs, and the respective responsible (even if null).
But I noticed that Hibernate is always parsing the query using INNER JOINS, so I only receive the first line of the result set.
My question: is there ANY way to instruct Hibernate to use LEFT JOINS, or I'll have to change my queries in the WHOLE application...?
|