RoomType和RoomState的主键是Integer,在get的时候忘记转换为Integer了:

         this .getHibernateTemplate().execute( new  HibernateCallback() {
            
public  Object doInHibernate(Session session)  throws  HibernateException {
                room.setType((RoomType) session.get(RoomType.
class , typeId));
                room.setState((RoomState) session.get(RoomState.
class , stateId));
                session.update(room);
                
return   null ;
            }
        });

没想到hibernate居然大动干做,抛出一大堆的exception

java.sql.SQLException: 索引中丢失  IN 或 OUT 参数::  1
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:
112 )
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:
146 )
    at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:
1681 )
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:
3280 )
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:
3329 )
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:
92 )
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:
139 )
    at org.hibernate.loader.Loader.getResultSet(Loader.java:
1669 )
    at org.hibernate.loader.Loader.doQuery(Loader.java:
662 )
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:
224 )
    at org.hibernate.loader.Loader.doList(Loader.java:
2145 )
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:
2029 )
    at org.hibernate.loader.Loader.list(Loader.java:
2024 )
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:
375 )
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:
308 )
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:
153 )
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:
1129 )
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:
79 )
    at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:
749 )
    at com.phopesoft.hms.room.service.impl.RoomServiceImpl$
3 .doInHibernate(RoomServiceImpl.java: 151 )
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:
366 )
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:
334 )

这样的错误真是让我一点莫不着头脑,还好从后台打出的hql看到了错误的信息

org.springframework.jdbc.UncategorizedSQLException: Hibernate operation:
 could not execute query; uncategorized SQLException 
for  SQL [
 ...
 SQL state [ null ]; error code [ 17041 ]; 索引中丢失  IN 或 OUT 参数:: 1 ;
 nested exception is java.sql.SQLException: 索引中丢失  IN 或 OUT 参数:: 
1

不就是没找到吗,干嘛要这样呢 02.gif 11.gif

将String类型转换为Integer就没事了
         this .getHibernateTemplate().execute( new  HibernateCallback() {
            
public  Object doInHibernate(Session session)  throws  HibernateException {
                room.setType((RoomType) session.get(RoomType.
class new  Integer(typeId)));
                room.setState((RoomState) session.get(RoomState.
class new  Integer(stateId)));
                session.update(room);
                
return   null ;
            }
        });