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. |