Hql left join on application problem

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.