---
title: "hibernateTemplate关于findByExample对entity类型的识别"
author: "lms168"
date: "2011-10-13T18:32:22Z"
tags: ["findByExample"]
categories: ["编程语言"]
slug: "hibernatetemplate-findbyexample-entity"
draft: false
lastmod: "2011-10-13T18:35:30Z"
id: 1195268
url: "https://lms168.iteye.com/blog/1195268"
---

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);
<span style="color:red">//注意没有给age赋值</span>
this.hibernateTemplate.findByExample(u);

}

<span style="color:darkblue">其生成的sql语句将会是：select from User where name=? and pwd=? and age=?</span><span style="color:red">
这里将age默认作为了查询条件，修改方法是将age类型换成Integer</span>