-->
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.  [ 5 posts ] 
Author Message
 Post subject: Possible bug in the Criteria API
PostPosted: Fri Mar 16, 2007 11:33 am 
Newbie

Joined: Fri Mar 16, 2007 6:50 am
Posts: 9
Location: Paris, France
Hi I think I found a bug using the Criteria API. I am using Hibernate 3.2.0.cr5 (according to the META-INF in hibernate3.jar) with Oracle9, thin driver and Oracle9 dialect
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 wrote the following

getHibernateTemplate().find("from Woffre woffre where rownum <= ? order by woffre.sid asc", 50);

... which produces a 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 work with an int...

Is this a (known ?) bug ? or just a misconfiguration?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 1:19 pm 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
The criteria api works fine
Maybe this is an oracle specific problem : are you sure of the dialect you use (there is two dialects for oracle)
What's the link between the criteria call and the hql one ? Does hibernate converts maxresult with rownum>? for oracle ?

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 1:27 pm 
Newbie

Joined: Fri Mar 16, 2007 6:50 am
Posts: 9
Location: Paris, France
I am using dialect org.hibernate.dialect.Oracle9Dialect for an Oracle 9 database

scesbron wrote:
What's the link between the criteria call and the hql one ? Does hibernate converts maxresult with rownum>? for oracle ?


yes, I copied/pasted the "where" clause displayed as a log when using the Criteria API


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 6:09 am 
Newbie

Joined: Fri Mar 16, 2007 6:50 am
Posts: 9
Location: Paris, France
OK, as nobody seems to know about this problem, I raised this issue : http://opensource.atlassian.com/project ... e/HHH-2509


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 7:41 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Just a tip : this is an open source project that cannot reproduce all the possible environments.
As your problem seems to be environment specific you may have to provide more informations for your jira.
At least hibernate developers need a test case that reproduce the problem. The best you can do is a patch that solve it but it is a lot more work

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.