天天看点

异常 --TypeMismatchException

从昨天晚上就一直遇到这个异常:感觉好怪,一条一条的找了很久 还是没有解决:

org.hibernate.TypeMismatchException: Provided id of the wrong type for class  com.demo.pojo.Userinfo. Expected:       
class java.lang.Integer, got class java.lang.String;       
数据库中并没有int类型的字段,为什么会这样?      
一字一句的找了一晚上,模模糊糊知道是类型转换为题,终于在今天找到解决方案咯^_-      
在DAO层 有这样一个方法      
public EL_TransIdTable Find_ById(String name){
	  return this.hibernateTemplate.get(EL_TransIdTable.class, name);//通過domain來修改對應的lastId
		
	 }
           
平时是传给hibernate int类型的id ,现在传给他的是string类型的name 难道他不认识string类型的name?还是给他整容变成int类型了?      
public EL_TransIdTable Find_ById(String name){
		 String hql="select * from EL_TransIdTable el_t where el_t.DomainId='"+name+"'";
		 List list =this.hibernateTemplate.find(hql);
		 if(list.size()==0){
			 System.out.println("沒有此用戶");
			 return null;
		 }else{
			 EL_TransIdTable el_t=(EL_TransIdTable)list.get(0);
			 return el_t;
		 }
	 }
           
这样子就不会报上诉异常了。……^_-