org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User. Expected: class java.lang.String, got class java.lang.Integer at org.hibernate.event.internal.Defau

出现org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User. Expected: class java.lang.String, got class java.lang.Integer at org.hibernate.event.internal.DefaultLoadEventListener.checkIdClass(DefaultLoadEventListen

这样的错误,可能是bean中的数据类型和hbm.xml中指定的主键生成策略不一致。

比如我在bean中,将uid写出字符串,而在hbm.xml中使用的是<generator class="native"/>这样就报错了。

原文地址:https://www.cnblogs.com/liaoxiaolao/p/9918050.html