当前位置: 代码迷 >> J2EE >> hirbernate分页出错解决办法
  详细解决方案

hirbernate分页出错解决办法

热度:50   发布时间:2016-04-22 02:10:34.0
hirbernate分页出错
数据库中的是sqlserver2000
Java code
Configuration con = new Configuration().configure();        SessionFactory sf = con.buildSessionFactory();        Session session = sf.openSession();        Query q = session.createQuery("from UserBean ");        q.setMaxResults(110);        q.setFirstResult(100);        List<UserBean> li = q.list();        for(UserBean ub : li) {            System.out.println(ub.getName());        }

这是写的测试
Java code
Hibernate:     select        top 210 userbean0_.pk_id as pk1_0_,        userbean0_.f_name as f2_0_,        userbean0_.f_money as f3_0_     from        t_money userbean0_2011-5-12 12:06:53 org.hibernate.type.NullableType nullSafeGet信息: could not read column value from result set: pk1_0_; Invalid column name pk1_0_.2011-5-12 12:06:53 org.hibernate.util.JDBCExceptionReporter logExceptions警告: SQL Error: 0, SQLState: 070092011-5-12 12:06:53 org.hibernate.util.JDBCExceptionReporter logExceptions严重: Invalid column name pk1_0_.Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)    at org.hibernate.loader.Loader.doList(Loader.java:2216)    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)    at org.hibernate.loader.Loader.list(Loader.java:2099)    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)    at com.lovo.text.PageText.main(PageText.java:21)Caused by: java.sql.SQLException: Invalid column name pk1_0_.    at net.sourceforge.jtds.jdbc.JtdsResultSet.findColumn(JtdsResultSet.java:906)    at net.sourceforge.jtds.jdbc.JtdsResultSet.getInt(JtdsResultSet.java:910)    at org.hibernate.type.IntegerType.get(IntegerType.java:28)    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)    at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1097)    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:565)    at org.hibernate.loader.Loader.doQuery(Loader.java:701)    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)    at org.hibernate.loader.Loader.doList(Loader.java:2213)    ... 8 more

这是暴的错误,如果把q.setFirstResult(100);去掉的话就不会报错,但数据就是从第一条开始取的

------解决方案--------------------
sqlserver2000的数据库名、表名和数据都和oracle一样么 要是一样的话看看sqlserver2000的方言 可能翻译sqlserver2000的生气了出错了
  相关解决方案