-->
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: Error message incorrect?
PostPosted: Thu May 31, 2007 1:55 pm 
Beginner
Beginner

Joined: Tue Jun 07, 2005 8:24 am
Posts: 33
Location: Cincinnati, OH
Suppose you try this...

Code:
Query q = session.createQuery("select x from Person x where x.name = :name");
q.setParameter(0,"thename");
List list = q.list();


You will get an IndexOutOfBoundsException which states:

"Remember that ordinal parameters are 1-based!"

However, the Hibernate documentation states (which is correct):

"Contrary to JDBC, Hibernate numbers parameters from zero."

Should I file a bug to fix the error message? I know why the exception happens, because there really are no ordinal parameters in the query string (changing ":name" to "?" fixes it), but the error message is misleading. It makes you think you need to pass in 1 instead of 0 to the setParameter() method. That, of course, does nothing to fix the problem.

Hibernate version: 3.2.2.ga


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 2:05 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
I'm looking at AbstractQueryImpl of Hibernate 3.2.4 SP1 and the code throws
Code:
IllegalArgumentException("No positional parameters in query: " + getQueryString() )


Top
 Profile  
 
 Post subject: Re: Error message incorrect?
PostPosted: Thu May 31, 2007 5:18 pm 
Beginner
Beginner

Joined: Tue Jun 07, 2005 8:24 am
Posts: 33
Location: Cincinnati, OH
Well, is that other error message used in the code anywhere? If so, it should be changed to "0-based" rather than "1-based".


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 6:01 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
No. Maybe it has been completely rewritten.

Here is the code:
Code:
   public Query setParameter(int position, Object val) throws HibernateException {
      if (val == null) {
         setParameter( position, val, Hibernate.SERIALIZABLE );
      }
      else {
         setParameter( position, val, determineType( position, val ) );
      }
      return this;
   }

and then it calls:
Code:
   public Query setParameter(int position, Object val, Type type) {
      if ( parameterMetadata.getOrdinalParameterCount() == 0 ) {
         throw new IllegalArgumentException("No positional parameters in query: " + getQueryString() );
      }
      if ( position < 0 || position > parameterMetadata.getOrdinalParameterCount() - 1 ) {
         throw new IllegalArgumentException("Positional parameter does not exist: " + position + " in query: " + getQueryString() );
      }
      int size = values.size();
      if ( position < size ) {
         values.set( position, val );
         types.set( position, type );
      }
      else {
         // prepend value and type list with null for any positions before the wanted position.
         for ( int i = 0; i < position - size; i++ ) {
            values.add( UNSET_PARAMETER );
            types.add( UNSET_TYPE );
         }
         values.add( val );
         types.add( type );
      }
      return this;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 6:29 pm 
Beginner
Beginner

Joined: Tue Jun 07, 2005 8:24 am
Posts: 33
Location: Cincinnati, OH
Okay, just wanted to make sure nobody else got confused like me. :)


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.