今天使用example查詢,結果發現設定的條件無效.
查詢代碼:

/***
*
* @param obj
* @param includezeros
* @return
*/
private criteria getcriteria( object obj, boolean includezeros) {
if (obj == null) {
return this.sessionfactory.getcurrentsession().createcriteria(clz);
} else {
example example = example.create(obj);
if (!includezeros) {
example = example.excludezeroes();
}
criteria criteria = this.sessionfactory.getcurrentsession()
.createcriteria(clz);
criteria.add(example);
return criteria;
}
}
測試

ordersdao ordersdao=(ordersdao)ctx.getbean("ordersdao");
orders orders=new orders();
orders.setbarcode("00001925");
list list=new arraylist();
// long count=ostypedao.listbypage(ostype, false, list, 0, 5);
long count=ordersdao.listbypage(orders, false, list, 0, 5);
system.out.println("count:"+count);
但是執行時,發現where後面是1=1,即設定的查詢條件(orders.setbarcode("00001925"))沒有起作用.
可能是代碼的問題
orders 結構如下:

* note:不允許修改表結構<br />table:orders<br />
* 訂單類
* @author huangwei
* @since 2014-09-02
*/
@entity
@table(name = "orders")
public class orders {
/***
* 條碼,訂單号
private string barcode;
* 本訂單返工次數,新單為0,返工累加∑1-n
private int serial;
@id
@column(name="order_id",unique=true)
public string getbarcode() {
return barcode;
public void setbarcode(string barcode) {
this.barcode = barcode;
}
後來發現突然發現其他字段沒問題,那麼barcode有什麼特殊的地方嗎?
再一看表,原來它是主鍵.