首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

org.hibernate.TypeMismatchException: Provided id of

2011-12-11 
紧急求助:postgre的serial类型的映射问题。我百思不得其解,为什么每次总出线这个错误。我已经照n个这样的例

紧急求助:postgre的serial类型的映射问题。
我百思不得其解,为什么每次总出线这个错误。我已经照n个这样的例子进行修改了。serial类型是映射成Integer类型的。可报的这个错误,实在搞不明白。哪位高人帮忙看看。
简单的一个查询语句:
Object   users   =   getHibernateTemplate().get(User.class,   user);


User.hbm.xml:
<?xml   version= "1.0 "?>
<!DOCTYPE   hibernate-mapping   PUBLIC
"-//Hibernate/Hibernate   Mapping   DTD   3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd "   >

<hibernate-mapping   package= "freeunite.hibernate ">
<class   name= "User "   table= "USER ">
<id
column= "ID "
name= "id "
type= "java.lang.Integer "
>
<generator   class= "native "   />
</id>
<property
column= "PASSWORD "
length= "30 "
name= "password "
not-null= "false "
type= "java.lang.String "
  />
<property
column= "REMARKS "
length= "50 "
name= "remarks "
not-null= "false "
type= "string "
  />
<property
column= "USER_ID "
length= "15 "
name= "userId "
not-null= "true "
type= "java.lang.String "
  />
<property
column= "ROLE "
length= "10 "
name= "role "
not-null= "false "
type= "java.lang.String "
  />
<property
column= "USER_NAME "
length= "20 "
name= "userName "
not-null= "false "
type= "java.lang.String "
  />
</class>
</hibernate-mapping>

User.java:
public   class   User   implements   Serializable   {

private   Integer   id;

private   String   userId;

private   String   userName;

private   String   password;

private   String   role;

private   String   remarks;

public   Integer   getId()   {
return   id;
}

public   void   setId(Integer   id)   {
this.id   =   id;
}

public   String   getPassword()   {
return   password;
}

public   void   setPassword(String   password)   {
this.password   =   password;
}

public   String   getRemarks()   {
return   remarks;
}

public   void   setRemarks(String   remarks)   {
this.remarks   =   remarks;
}

public   String   getRole()   {
return   role;
}

public   void   setRole(String   role)   {
this.role   =   role;
}

public   String   getUserId()   {
return   userId;
}

public   void   setUserId(String   userId)   {
this.userId   =   userId;
}

public   String   getUserName()   {
return   userName;
}

public   void   setUserName(String   userName)   {
this.userName   =   userName;


}

}

错误信息:
org.hibernate.TypeMismatchException:   Provided   id   of   the   wrong   type.   Expected:   class   java.lang.Integer,   got   class   freeunite.hibernate.User
at   org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
at   org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at   org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at   org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at   org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:467)
at   org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:369)
at   org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:461)
at   org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:455)
at   freeunite.dao.UserDAOImpl.findUserById(UserDAOImpl.java:21)
at   freeunite.service.LoginServiceImpl.findUserById(LoginServiceImpl.java:19)
at   freeunite.service.LoginServiceImpl$$FastClassByCGLIB$$4f9b58de.invoke( <generated> )
at   net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at   org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:693)
at   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
at   org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at   org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:628)
at   freeunite.service.LoginServiceImpl$$EnhancerByCGLIB$$6ae9edaa.findUserById( <generated> )
at   freeunite.action.LoginAction.login(LoginAction.java:54)
at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native   Method)



[解决办法]
ding

热点排行