Hibernate: Use disjunction and conjunction to construct complex query Conditions

Source: Internet
Author: User

Disjunction and conjunction are logical or logical and can be used to construct complex SQL query conditions. The example is as follows:

Private void checkbsc_lj (criteria querycriteria)
{
Disjunction disjunction = restrictions. disjunction ();
Criterion Cirterion = restrictions. sqlrestriction ("simulportcapacity <simulportcapacityocupied". tolowercase ());
Disjunction. Add (Cirterion );
Cirterion = restrictions. sqlrestriction ("adslportcapacity <adslportcapacityoccupied". tolowercase ());
Disjunction. Add (Cirterion );
Cirterion = restrictions. sqlrestriction ("lanportcapacity <lanportcapacityoccupied". tolowercase ());
Disjunction. Add (Cirterion );

// ONU port. At least one port must be input.
Conjunction conjunction = restrictions. conjunction ();
Cirterion = restrictions. eq ("lanportcapacity", 0 );
Conjunction. Add (Cirterion );
Cirterion = restrictions. eq ("simulportcapacity", 0 );
Conjunction. Add (Cirterion );
Cirterion = restrictions. eq ("adslportcapacity", 0 );
Conjunction. Add (Cirterion );

Disjunction. Add (conjunction );
Querycriteria. Add (disjunction );
}

The constructed conditions are as follows:
Select *
From AAAA this _
Where (simulportcapacity <simulportcapacityocupied or
Adslportcapacity <adslportcapacityoccupied or
Lanportcapacity <lanportcapacityoccupied or
(This _. lanportcapacity =? And this _. simulportcapacity =? And
This _. adslportcapacity = ?))

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.