-->
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: query.setParameter() causing exception with 3.1rc3 !
PostPosted: Wed Nov 23, 2005 6:26 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
Hibernate version: 3.1rc3

I get error with on setParameter() statement!

Query query = hsession.createQuery("from StUserdaten as b where b.login = ?1");
query.setParameter(0, name);

Code:
Caused by: java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
   at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterDescriptor(ParameterMetadata.java:55)
   at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterExpectedType(ParameterMetadata.java:61)
   at org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:378)
   at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:362)


debug at org.hibernate.engine.query.ParameterMetadata:54
ordinalDescriptors.toString() says:

<toString() unavailable. Component type not loaded>

What is the problem please?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 6:32 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 4:53 pm
Posts: 41
Location: Netherlands
The message says:

Code:
Remember that ordinal parameters are 1-based!


So.. use 1 - based ;)

like:
Code:
query.setParameter(1, name);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 6:49 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
no, if you look into hibernate code you will find out that
1) setParameter("index", )
2) the index is increased by one at AbstractQueryImpl.java:378

I got back to using "?" instead of "?1" for this single parameter and no more exception occured.

Not sure if this is the concept behind...


momania wrote:
The message says:

Code:
Remember that ordinal parameters are 1-based!


So.. use 1 - based ;)

like:
Code:
query.setParameter(1, name);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 6:54 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 4:53 pm
Posts: 41
Location: Netherlands
axismundi wrote:
I got back to using "?" instead of "?1" for this single parameter and no more exception occured.

Not sure if this is the concept behind...

I think it is.

According to http://hibernate.org/hib_docs/v3/refere ... parameters
you're using the right format now. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 3:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
the ejb3 form that you are trying ('?1') is actually handled within the Hibernate code as a named parameter. So for:
Code:
Query query = hsession.createQuery("from StUserdaten as b where b.login = ?1");
query.setParameter(0, name);

You'd actually use query.setParameter( "1", name ) instead.

The message about "1-based" is misleading here. It refers to the fact the the metadata for parameters is actually indexed by their sql positions (which is 1-based).


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.