Parameterization of hibernate fuzzy query

Source: Internet
Author: User
Parameterization of hibernate fuzzy query

In fact, the root cause of this problem is that I don't know much about the use of hibernate. It's right to change it to this: from project O where 1 = 1 and O. isdeleted =? And O. prjname like ?; Query. setstring (I, "%" + actual query condition + "%"); note that there are no single quotation marks on the left and right of the first percent in the parameter, this is different from writing SQL statements in peacetime. You should also know the differences between the two points.

Hql: from project O where 1 = 1 and prj_name like '% strcond %'; // here, prj_name should be the actual field name in the database table hql: from Project O where 1 = 1 and O. prj_name like '% strcond %'; // prj_name should be the attribute name of the object class.

Hql: from project O where 1 = 1 and prj_name like '? '; // Here? The placeholder parameter hql: from project O where 1 = 1 and prj_name like ?; // When you set the parameter value, a single quotation mark is automatically added to both sides of the parameter value.

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.