Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.2.4 and 3.3.1 GA
Mapping documents: native query
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterDescriptor(ParameterMetadata.java:79)
at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterExpectedType(ParameterMetadata.java:85)
at org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:421)
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:393)
Name and version of the database you are using: Oracle 10.2.0.4
The generated SQL (show_sql=true):
select t.user_id, t.type from table t where t.user_id = ? and t.type = 'Customer call'
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html
Hi!
I found a slight bug in
Code:
org.hibernate.engine.query.ParameterParser.java
public static void parse(String sqlString, Recognizer recognizer) throws QueryException
procedure wich cause the above query to throw a
Code:
java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
exception when registering the first parameter.
This is caused by line in ParameterParser.java:
Code:
boolean hasMainOutputParameter = sqlString.indexOf("call") > 0 && sqlString.indexOf("?") < sqlString.indexOf("call") && sqlString.indexOf("=") < sqlString.indexOf("call");
which examines the query string and checks for word "call". This causes the exception because the first parameter is before the second condition wich unfortunately contains the word "call", so the first parameter is recognized as main output parameter. If I rewrite my query and use following order:
Code:
select t.user_id, t.type from table t where t.type = 'Customer call' and t.user_id = ?
everything works fine. This is now the only work-around I've found (except of using named parameters, wich works both case), but with large tables and queries this could affect the query performance if condition order affects index using, filter order, etc. in the database engine.
Can this issue be corrected somehow, or should I use named parameters instead of ordinal based ones?
Thank you!
Regards,
gizola