Hibernate version:3.1.2
Name and version of the database you are using:Microsoft SQL Server 2000
I have 2 tables: Parent & Children.
Parent structure: id(int), name(string). Primary key: id.
Children structure: parentid(int), type(int), name(string). Primary key: parentid, type.
"Children.parentid" is related to "Parent.id".
I can use SQL to left join a certain "type" of "Children": "SELECT * FROM Parent LEFT OUTER JOIN Children ON Parent.id=Children.parentid AND Children.type=?" or "SELECT * FROM Parent LEFT OUTER JOIN (SELECT * FROM Children WHERE type=?) ON Parent.id=Children.parentid".
How to use HQL to do the same thing? It is wrong if we write HQL as "from Parent left join Parent.children Children where Children.type is null or Children.type=:type". It is the same as the SQL "SELECT * FROM Parent LEFT OUTER JOIN Children ON Parent.id=Children.parentid WHERE Children.type IS NULL OR Children.type=:type". The HQL doesn't equals the SQL above.
Hibernate also doesn't support such HQLs: "from Parent left join (select Children from Parent.children as Children where Children.type=:type)" & "from Parent left join Parent.children as Children on Children.type=:type".
How to use HQL to do the same thing as the SQL metioned above?
THANKS A LOT!
|