NET Pick one:
Sql:select c.* from card C left JOIN score s on s.card_id = C.id and S.invalid_date >=curdate () where s.id is null
To use the LEFT join in hibernate you must declare an association mapping, where the association is One-to-many, a set scores is built in the card, and then configured
<set name= "scores" cascade= "None" where= "Valid_date >= curdate ()" >
<key column= "card_id"/>
<one-to-many class= "Score"/>
</set>
The only special thing is that the WHERE,HQL cannot be written on, so the conditions on it are written in the where, where is the field name and the SQL for the different databases, which results in a bit more effort between the porting of the different databases.
HQL is as follows: Select C from card C left join C.scores s where s.id is null
The problem is: The key configured in set is not another table keyword, the condition does not need to use key, and how to use it. The present is the problem, ah, can not find a solution, the problem first recorded. Have time to look again
NET picks the second:
There are 2 table: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 and Parent.id connections
SQL can be written as 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
<class>
....
<set name= "Children" inverse= "true" >
<key column= "parent_id"/>
<one-to-many class= "Parent"/>
<filter name= "TypeFilter"/>
</set>
</class>
<filter-def name= "TypeFilter" condition= "Type=:type" >
<filter-param name= "type" type= "string"/>
</filter-def>
Session.enablefilter ("TypeFilter"). Setparameter ("type", "xxxxxxxx");
List List=session.createquery ("Select p from Parent p left join P.children C"). List ();
The problem is that my DB access layer uses simplehibernatetemplate, and the filter here knows how to use it.
HQL is not very familiar with the record of a problem.