-->
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.  [ 1 post ] 
Author Message
 Post subject: Parameter problem with special native query
PostPosted: Thu Apr 16, 2009 10:54 am 
Newbie

Joined: Thu Apr 16, 2009 10:34 am
Posts: 1
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


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

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.