Criteria.setMaxResults(int) broken with Oracle9Dialect, only works with a long in a HQL
query
---------------------------------------------------------------------------------------------
Key: HHH-2509
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2509
Project: Hibernate3
Type: Bug
Components: query-criteria
Versions: 3.2.0.cr5
Environment: Windows XP, Oracle 9, Spring 2.0.3, Hibernate 3.2.0.cr5
Reporter: Gabriel Goïc
Willing to extract 50 random elements from my database, I wrote the following snippet of
code:
Criteria crit = getSession().createCriteria(Woffre.class);
crit.setMaxResults(50);
crit.addOrder(Order.asc("sid"));
return crit.list();
As you can see, there's nothing particular here. But executing this code gives the
following error:
org.hibernate.exception.GenericJDBCException: could not execute query
at
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2160)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2041)
at org.hibernate.loader.Loader.list(Loader.java:2036)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at
fr.apec.proto.server.dao.impl.WOffreDAOImpl.loadFirst50WOffres(WOffreDAOImpl.java:55)
(...)
Caused by: java.sql.SQLException: Missing IN or OUT parameter at index:: 1
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.driver.OracleStatement.checkBindsInAndOut(OracleStatement.java:1971)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2812)
at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)
(...)
So, I decided to use HQL to work around this problem and copied/pasted the
"where" clause displayed as a log when using the Criteria API :
getHibernateTemplate().find("from Woffre woffre where rownum <= ? order by
woffre.sid asc", 50);
... which produces a java.lang.ClassCastException with java.lang.Integer whereas the
following
getHibernateTemplate().find("from Woffre woffre where rownum <= ? order by
woffre.sid asc", (long)50);
... just works fine
It seems that Criteria.setMaxResults(int) should take a long instead of an int, as the
Criteria API seems not able to get the conversion done, which causes a crash; or maybe the
underlying implementation should be able to work with an int...
PS: I first posted this problem on the hibernate users forum :
http://forum.hibernate.org/viewtopic.php?t=972225
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira