Hibernate异常:Provided id of the wrong type for class

进行CRUD出现以下异常

 

 
 
  1. 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  
  2.     org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:135)  
  3.     org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)  
  4.     org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)  
  5.     org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)  
  6.     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  7.     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
  8.     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
  9.     java.lang.reflect.Method.invoke(Method.java:597)  
  10.     org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344)  
  11.     $Proxy12.get(Unknown Source)  
  12.     org.liyy.base.Base.findById(Base.java:98)  
  13.     org.liyy.page.action.CartAction.addCart_db(CartAction.java:203)  
  14.     org.liyy.page.action.CartAction.addCart(CartAction.java:42)  
  15.     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  16.     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
  17.     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
  18.     java.lang.reflect.Method.invoke(Method.java:597)  

原因是:实体类中主键的类型设置和数据库中不匹配。

解决方法:

1.查看实体类中主键的类型。

2.查看数据库中主键设置的类型。

3.统一类型即可解决

猜你喜欢

转载自tbatm.iteye.com/blog/1727489