你好,我是新來Hibernate和我正在試圖執行和使用Eclipse,但LogicalExpression將呈現休眠條件查詢()方法的錯誤,如錯誤「和」休眠標準的方法
在類型限制的方法和(標準,標準)是不適用的參數(判定基準,標準)
package actions;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.LogicalExpression;
import org.hibernate.criterion.Restrictions;
public class Andrestriction {
public static void main(String[] args) {
// TODO Auto-generated method stub
SessionFactory sf=new Configuration().configure().buildSessionFactory();
Session sn=sf.openSession();
Criteria cr=sn.createCriteria(PC.class);
Criteria id=(Criteria) Restrictions.gt("id",11);
Criteria os=(Criteria) Restrictions.ilike("os","d%");
LogicalExpression and=Restrictions.and(id,os); //This line will show error like this:-
//The method and(Criterion, Criterion) in the type Restrictions is not
//applicable for the arguments (Criteria, Criteria)
cr.add(and);
List l=cr.list();
Iterator itr=l.iterator();
while(itr.hasNext())
{
PC p=(PC)itr.next();
System.out.println(p.getId()+"\t"+p.getName()+"\t"+p.getOs());
}
sn.close();
}
}
我想使用和爆擊eria在我的Query.Please告訴我如何解決這個問題。 預先感謝
代碼得到執行..感謝gomyes。 – 2014-09-01 21:10:25