进行CRUD出现以下异常
- org.hibernate.TypeMismatchException: Provided id of the wrong type for class org.liyy.model.Shop_books_group. Expected: class java.lang.String, got class java.lang.Integer
- org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:135)
- org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
- org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
- org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
- sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- java.lang.reflect.Method.invoke(Method.java:597)
- org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344)
- $Proxy12.get(Unknown Source)
- org.liyy.base.Base.findById(Base.java:98)
- org.liyy.page.action.CartAction.addCart_db(CartAction.java:203)
- org.liyy.page.action.CartAction.addCart(CartAction.java:42)
- sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- java.lang.reflect.Method.invoke(Method.java:597)
原因是:实体类中主键的类型设置和数据库中不匹配。
解决方法:
1.查看实体类中主键的类型。
2.查看数据库中主键设置的类型。
3.统一类型即可解决