-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: HQL max results and Oracle
PostPosted: Wed Dec 17, 2003 9:20 pm 
Newbie

Joined: Thu Dec 11, 2003 7:20 pm
Posts: 4
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 9:51 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
hm...
find 10 differencies between SQL query with and without setMaxResult()

You pasted the same query twice - it does not limit number of results.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.