I'm using Hibernate with Oracle EE 8.0.5.0.0. I'm having a problem using the HQL and setMaxResults(). Here's the method to retrieve information from the database:
Session hibernateSession = _hibernateSessionFactory.openSession();
List list = null;
try {
Query query = hibernateSession.createQuery("from Press as press where press.releaseDate < ? order by press.releaseDate desc");
query.setTimestamp(0, new Date(System.currentTimeMillis()));
query.setMaxResults(maxResults);
list = query.list();
} finally {
hibernateSession.close();
}
return list;
This generates the following SQL:
Hibernate: select press0_.ID as ID, press0_.TITLE as TITLE, press0_.DESCRIPTION as DESCRIPT3_, press0_.RELEASE_DATE as RELEASE_4_, press0_.CREATED_DATE as CREATED_5_, press0_.UPDATED_DATE as UPDATED_6_ from PRESS press0_ where (press0_.RELEASE_DATE<? ) order by press0_.RELEASE_DATE desc
which throws the following exception:
net.sf.hibernate.JDBCException: Could not execute query
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1476)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:45)
at ai.event.calendar.EventCalendarDatabase.load(EventCalendarDatabase.java:58)
at ai.event.calendar.servlets.UpcomingEventsServlet.doGet(UpcomingEventsServlet.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:162)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:479)
Caused by: java.sql.SQLException: ORA-00907: missing right parenthesis
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1451)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:651)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2110)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2324)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:421)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:365)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:790)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:128)
at net.sf.hibernate.loader.Loader.list(Loader.java:918)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:983)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1473)
... 12 more
If I comment out the line:
//query.setMaxResults(maxResults);
The following SQL is generating and the query runs fine:
select press0_.ID as ID, press0_.TITLE as TITLE, press0_.DESCRIPTION
as DESCRIPT3_, press0_.RELEASE_DATE as RELEASE_4_, press0_.CREATED_DATE as CREATED_5_, press0_.UPDATED_DATE as UPDATED_6_ from PRESS press0_ where (press0_.RELE
ASE_DATE<? ) order by press0_.RELEASE_DATE desc
My best guess is that Oracle does not like the sub-select, but I'm having trouble deciphering the problem.
|