使用spring的HibernateDaoSupport的时候,报错如下:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at org.hibernate.type.IntegerType.set(IntegerType.java:64) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
public class User { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
dao层的代码如下:
public void select(String id) { List result = this.getHibernateTemplate().find("from User where id=?", new Object[] { id }); }
public void select(int id) { List result = this.getHibernateTemplate().find("from User where id=?", new Object[] { id }); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
spring中使用HibernateTemplate或HibernateDaoSupport报类型转换错误
原文地址:http://blog.csdn.net/aitangyong/article/details/46833681