Hey,
Here is the problem. Lets say we have a Product class which is mapped to 'product' table. And there is a 'supplier' property in it which is mapped as many to one to 'Person' class. supplier is a NULLABLE property...
@Entity @Table(name="product") public class Product { ... ...
@ManyToOne @JoinColumn(name = "bp_supplier_id", nullable = true, insertable=true, updatable=true) private Person supplier; ... }
So, here is the problem. I am trying to select products and order the result by the supplier first name - something like this:
FROM Product product ORDER BY product.supplier.firstName
As a result we will get all products EXCEPT those where the supplier is NULL. So to have also those products included in the result (where supplier is null) I've always used CASE WHEN clause:
FROM Product product ORDER BY CASE WHEN product.supplier IS NULL THEN 0 ELSE product.supplier.firstName END
So this worked fine while I used mysql 5.0.X.
Currently I am using newer versions of mysql (5.5.X) - and now provided above example DOESN'T WORK as it should be --- AGAIN products with the supplier = null, doesn't available in the result List...
I'm kindly asking, to share with me the way you used to go with in such situations - when you are going to order by the result by any property of the 'many-to-one' property which is NULLABLE.
|