0

I would like to retrieve some data from 2 different tables. They are named 'A' and 'B'. There is also another table called 'C'.

Both A and B have a reference to 'C', but 'C' does NOT have a reference neither to A nor B.

My SQL command would be something like this:

select 
    A.x,
    A.y,
    B.z 
from 
    A
LEFT OUTER JOIN C ON C.i = A.i
LEFT OUTER JOIN B ON B.i = C.i

The thing is: I have some data i need in table A, and some data on table B. I need to retrieve all data from table A where a property from table A is equal to a property of the table B, and therefore some data from table B. Thats easy, really simple HQl command (easier with LINQ):

select a.x, a.y, b.z
from A as a, B as b
where a.x = b.x

But the problem is: i also need to retrieve the data from A when a.x is NULL. I would of course get a null value from b.x

I tried using DefaultIfEmpty() on LINQ, but since i use session.Query() over an entity, DefaultIfEmpty is not implemented yet in NH 3.

How can i write that in HQL?

2

1 Answer 1

1

You can't use left joins in HQL for unmapped relationships.

You can just use a SQLQuery for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.