The online example of fuzzy query of long data in Hibernate is better. It is written here for discussion. Note the following:
Currently, only restrictions. sqlrestriction is used.
The example is as follows:
// This mainly determines whether the query is complete.
If (searchcondition. getisselectedallarea ()! = NULL & searchcondition. getisselectedallarea (). Equals ("On ")){
// Criteria. createalias ("area", "O "). add (restrictions. like ("O. ID "," % "+ searchcondition. getareaid (). tostring (). substring (0, 4) + "% "));
Criteria. createalias ("area", "O"). Add (restrictions. sqlrestriction ("area_id like (?) "," % "+ Searchcondition. getareaid (). tostring (). substring (0, 4) +" % ", hibernate. String ));
} Else {
If (searchcondition. getareaid ()! = NULL &&! Searchcondition. getareaid (). Equals ("")){
Criteria. createalias ("area", "O"). Add (restrictions. eq ("O. ID", searchcondition. getareaid ()));
}
}
The Code on the attachment is as follows:
Public list findbillqueryresult (searchcondition, string billtypekey, searchdatebean ){
Detachedcriteria criteria;
If (domsglobalconstant. dict_key_for_bill_type_turninbill.equals (billtypekey )){
Criteria = detachedcriteria. forclass (turnbill. Class );
} Else if (domsglobalconstant. dict_key_for_bill_type_movebill.equals (billtypekey )){
Criteria = detachedcriteria. forclass (movebill. Class );
} Else if (domsglobalconstant. dict_key_for_bill_type_oldbill.equals (billtypekey )){
Criteria = detachedcriteria. forclass (oldbill. Class );
} Else if (domsglobalconstant. dict_key_for_bill_type_wasterbill.equals (billtypekey )){
Criteria = detachedcriteria. forclass (wasterbill. Class );
} Else {
Criteria = detachedcriteria. forclass (drawbill. Class );
}
If (searchcondition. getapplyaccount ()! = NULL &&! Searchcondition. getapplyaccount (). Equals ("")){
Criteria. createalias ("materialman", ""). add (restrictions. like (". staffaccount "," % "+ searchcondition. getapplyaccount () + "% "). ignorecase ());
}
If (searchcondition. getacountaccount ()! = NULL &&! Searchcondition. getacountaccount (). Equals ("")){
Criteria. createalias ("accounter", "B "). add (restrictions. like ("B. staffaccount "," % "+ searchcondition. getacountaccount () + "% "). ignorecase ());
}
If (searchcondition. getapproveaccount ()! = NULL &&! Searchcondition. getapproveaccount (). Equals ("")){
Criteria. createalias ("leader", "C "). add (restrictions. like ("C. staffaccount "," % "+ searchcondition. getapproveaccount () + "% "). ignorecase ());
}
If (searchcondition. getitemmanageraccount ()! = NULL &&! Searchcondition. getitemmanageraccount (). Equals ("")){
Criteria. createalias ("manager", "D "). add (restrictions. like ("D. staffaccount "," % "+ searchcondition. getitemmanageraccount () + "% "). ignorecase ());
}
If (domsglobalconstant. dict_key_for_bill_type_movebill.equals (billtypekey )){
If (searchcondition. getplanaccount ()! = NULL &&! Searchcondition. getplanaccount (). Equals ("")){
Criteria. createalias ("indispatcher", "P "). add (restrictions. like ("P. staffaccount "," % "+ searchcondition. getplanaccount () + "% "). ignorecase ());
}
If (searchcondition. getplanaccount ()! = NULL &&! Searchcondition. getplanaccount (). Equals ("")){
Criteria. createalias ("outdispatcher", "Q "). add (restrictions. like ("Q. staffaccount "," % "+ searchcondition. getplanaccount () + "% "). ignorecase ());
}
If (searchcondition. getstoreaccount ()! = NULL &&! Searchcondition. getstoreaccount (). Equals ("")){
Criteria. createalias ("outstoreman", "R "). add (restrictions. like ("R. staffaccount "," % "+ searchcondition. getstoreaccount () + "% "). ignorecase ());
}
If (searchcondition. getstoreaccount ()! = NULL &&! Searchcondition. getstoreaccount (). Equals ("")){
Criteria. createalias ("instoreman", "S "). add (restrictions. like ("s. staffaccount "," % "+ searchcondition. getstoreaccount () + "% "). ignorecase ());
}
If (searchcondition. getstorehousename ()! = NULL &&! Searchcondition. getstorehousename (). Equals ("")){
Criteria. createalias ("instorehouse", "T "). add (restrictions. like ("T. storehousename "," % "+ searchcondition. getstorehousename () + "% "). ignorecase ());
}
If (searchcondition. getstorehousename ()! = NULL &&! Searchcondition. getstorehousename (). Equals ("")){
Criteria. createalias ("outstorehouse", "U "). add (restrictions. like ("U. storehousename "," % "+ searchcondition. getstorehousename () + "% "). ignorecase ());
}
} Else {
If (searchcondition. getplanaccount ()! = NULL &&! Searchcondition. getplanaccount (). Equals ("")){
Criteria. createalias ("dispatcher", "E "). add (restrictions. like ("e. staffaccount "," % "+ searchcondition. getplanaccount () + "% "). ignorecase ());
}
If (searchcondition. getstoreaccount ()! = NULL &&! Searchcondition. getstoreaccount (). Equals ("")){
Criteria. createalias ("storeman", "F "). add (restrictions. like ("F. staffaccount "," % "+ searchcondition. getstoreaccount () + "% "). ignorecase ());
If (searchcondition. getstorehousename ()! = NULL &&! Searchcondition. getstorehousename (). Equals ("")){
Criteria. createalias ("storehouse", "n "). add (restrictions. like ("N. storehousename "," % "+ searchcondition. getstorehousename () + "% "). ignorecase ());
}
}
}
If (searchcondition. getapplycode ()! = NULL &&! Searchcondition. getapplycode (). Equals ("")){
Criteria. Add (restrictions. Like ("applycode", "%" + searchcondition. getapplycode () + "%"). ignorecase ());
}
If (searchcondition. getbillcode ()! = NULL &&! Searchcondition. getbillcode (). Equals ("")){
Criteria. Add (restrictions. Like ("billcode", "%" + searchcondition. getbillcode () + "%"). ignorecase ());
}
If (searchcondition. getbillstatus ()! = NULL &&! Searchcondition. getbillstatus (). Equals ("")){
Criteria. createalias ("currentstatus", "H"). Add (restrictions. eq ("H. ID", searchcondition. getbillstatus ()));
}
If (searchcondition. getwoflag ()! = NULL &&! Searchcondition. getwoflag (). Equals ("")){
Criteria. createalias ("woflag", "I "). add (restrictions. like ("I. value "," % "+ searchcondition. getwoflag () + "% "). ignorecase ());
}
If (searchcondition. getitemcode ()! = NULL &&! Searchcondition. getitemcode (). Equals ("")){
Criteria. createalias ("item", "J "). add (restrictions. like ("J. itemcode "," % "+ searchcondition. getitemcode () + "% "). ignorecase ());
}
If (searchcondition. getitemname ()! = NULL &&! Searchcondition. getitemname (). Equals ("")){
Criteria. createalias ("item", "K "). add (restrictions. like ("K. itemname "," % "+ searchcondition. getitemname () + "% "). ignorecase ());
}
If (searchcondition. getengineername ()! = NULL &&! Searchcondition. getengineername (). Equals ("")){
Criteria. createalias ("engineer", "L "). add (restrictions. like ("L. engineername "," % "+ searchcondition. getengineername () + "% "). ignorecase ());
}
If (searchcondition. getevidence ()! = NULL &&! Searchcondition. getevition (). Equals ("")){
Criteria. Add (restrictions. Like ("cause", "%" + searchcondition. getevition () + "%"). ignorecase ());
}
If (searchcondition. getapplydept ()! = NULL &&! Searchcondition. getapplydept (). Equals ("")){
Criteria. createalias ("Dept", "M "). add (restrictions. like ("M. departmentname "," % "+ searchcondition. getapplydept () + "% "). ignorecase ());
}
// This mainly determines whether the query is complete.
If (searchcondition. getisselectedallarea ()! = NULL & searchcondition. getisselectedallarea (). Equals ("On ")){
// Criteria. createalias ("area", "O "). add (restrictions. like ("O. ID "," % "+ searchcondition. getareaid (). tostring (). substring (0, 4) + "% "));
Criteria. createalias ("area", "O"). Add (restrictions. sqlrestriction ("area_id like (?) "," % "+ Searchcondition. getareaid (). tostring (). substring (0, 4) +" % ", hibernate. String ));
} Else {
If (searchcondition. getareaid ()! = NULL &&! Searchcondition. getareaid (). Equals ("")){
Criteria. createalias ("area", "O"). Add (restrictions. eq ("O. ID", searchcondition. getareaid ()));
}
}
Try {
Toaccessdate;
Toaccessdate = new toaccessdate (searchdatebean );
// Process the query by Time
Criteria = toaccessdate. accessdate (criteria, searchdatebean );
// Process the total entry amount
Criteria = toaccessdate. accesssum (criteria, searchdatebean );
} Catch (exception e ){
E. printstacktrace ();
}
Criteria. Add (restrictions. eq ("deleteflage", globalconstant. del_flag_false ));
If (searchcondition. getmmcode ()! = NULL &&! Searchcondition. getmmcode (). Equals ("") | searchcondition. getmmname ()! = NULL &&! Searchcondition. getmmname (). Equals ("")){
Criteria. createcriteria ("trademmitemlist "). createalias ("material", "M "). add (restrictions. like ("M. materialcode "," % "+ searchcondition. getmmcode () + "% "). ignorecase ()). add (restrictions. like ("M. materialname "," % "+ searchcondition. getmmname () + "% "). ignorecase ());
}
Criteria. addorder (order. ASC ("applycode "));
Return abstractmmitemdao. findbycriteria (criteria );
}