主题:参考中的例子关于HQL语句的问题
时间: 2020-08-27来源:ITEYE
前景提要
相关推荐: 十分钟在jb里面运行hibernate的简单例子。 [求助]访问数据库报错,不知道什么原因,请指点…… 解决了我请客吃饭。sqlserver数据库的Blob无法解决读出问题。 HQL语法大全,并带有详细的例子 Hibernate中HQL语句的left join的例子详解 hibernate学习笔记之使用hql hibernate 直接执行hql语句的代码写法 Hibernate Hql查询语句总结
推荐群组: JBPM @net
更多相关推荐
Hibernate 我在Hibernate2的参考Blog例子中有这样一段查询语句:public List listAllBlogNamesAndItemCounts(int max) throws HibernateException { Session session = _sessions.openSession(); Transaction tx = null; List result = null; try { tx = session.beginTransaction(); Query q = session.createQuery("select blog.id, blog.name, count (blogItem) " +" from Blog as blog " +" left outer join blog.items as blogItem " +" group by blog.name, blog.id " +" order by max(blogItem.datetime) "); q.setMaxResults(max);//?? result = q.list(); tx.commit(); } catch (HibernateException he) { if (tx!=null) tx.rollback(); throw he; } finally { session.close(); } return result; } 我运行时报错: Hibernate: select blog0_.BLOG_ID as x0_0_, blog0_.NAME as x1_0_, count(items1_.B LOG_ITEM_ID) as x2_0_ from BLOGS blog0_ left outer join BLOG_ITEMS items1_ on bl og0_.BLOG_ID=items1_.BLOG_ID group by blog0_.NAME , blog0_.BLOG_ID order by ma x(items1_.DATE_TIME) limit ?, ? 2003-9-29 13:08:44 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 警告: SQL Error: 170, SQLState: HY000 2003-9-29 13:08:44 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 严重: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]第 1 行: 'limit' 附 近有语法错误。 2003-9-29 13:08:44 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 警告: SQL Error: 16945, SQLState: HY000 2003-9-29 13:08:44 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 严重: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]游标未声明。 2003-9-29 13:08:44 net.sf.hibernate.JDBCException <init> 严重: Could not execute query java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]第 1 行: 'limit' 附近有语法错误。 at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source ) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unkn own Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Sour ce) at com.microsoft.jdbc.sqlserver.tds.TDSCursorRequest.openCursor(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown S ource) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown So urce) at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown So urce) at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:71) at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:551) at net.sf.hibernate.loader.Loader.doFind(Loader.java:140) at net.sf.hibernate.loader.Loader.find(Loader.java:620) at net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:928) at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1343) at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:76) at eg.BlogMain.listAllBlogNamesAndItemCounts(BlogMain.java:136) at eg.BlogMain.main(BlogMain.java:211) =============================================== 如果我把 q.setMaxResults(max);一句删除却能运行!此函数是什么意思?我该如何设置?

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行