hibernateTemplate關於findByExample對entity類型的識別

findByExample()使用時得出結論:
1.不支持主鍵
2.不支持關聯
3.不支持NULL
4.對於基本類型(char,int。。。。)將會默認作爲查詢條件
如:
@Entity
@Table
public class User{
private int id;
private String name;
private String pwd;
private int age;
//getter/setter.....


public void UserDaoImpl(){
......
User u=new User();
u.set(name);
u.set(pwd);
[color=red]//注意沒有給age賦值[/color]
this.hibernateTemplate.findByExample(u);

}

[color=darkblue]其生成的sql語句將會是:select from User where name=? and pwd=? and age=?[/color][color=red]
這裏將age默認作爲了查詢條件,修改方法是將age類型換成Integer[/color]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章