hibernate 错误:Provided id of the wrong type for class com.lhaix.pojo.Test. Expected: class java.la

hibernate 错误:Provided id of the wrong type for class com.lhaix.pojo.Test. Expected: class java.la

 

错误:Provided id of the wrong type for class com.lhaix.pojo.Test. Expected: class java.lang.Long, got class java.lang.Integer

原因是传入的是Integer类型的参数,它需要的是Long类型的参数。

在Hibernate里,只要Number(8)以上的都是用Long类型。

我的代码是:Test test = (Test)session.get(Test.class, 1);

这么写传的是Integer。

应该这么写:Test test = (Test)session.get(Test.class, 1L);

或者:Test test = (Test)session.get(Test.class, (long)1);

等等写法

 

转自: http://hi.baidu.com/lhaix/item/067d570a2b625adf73e676ea

 

你可能感兴趣的:(hibernate 错误:Provided id of the wrong type for class com.lhaix.pojo.Test. Expected: class java.la)