-->
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.  [ 2 posts ] 
Author Message
 Post subject: setParameter & Remember that ordinal parameters are 1-ba
PostPosted: Wed Aug 27, 2008 11:58 am 
Newbie

Joined: Wed Aug 27, 2008 11:40 am
Posts: 2
Quote:
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:397)
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:369)
at *****.common.util.HibernateDAO.listQuery(HibernateDAO.java:421)
at *****.common.util.HibernateDAO.listByConstraint(HibernateDAO.java:403)
at *****.common.util.HibernateDAO.listByConstraint(HibernateDAO.java:384)
at *****.clientmgmt.dao.ClientDAOImpl.getClient(ClientDAOImpl.java:104)
at *****.test.dao.ClientDAOTest.insertAndCheck(ClientDAOTest.java:189)
at *****.test.dao.ClientDAOTest.testInsertMutualFundClient(ClientDAOTest.java:333)




We're using Hibernate 3, and I'm making sure a subclass MutualFund is persisting with this JUnit test. Due to the above exception, it never gets past the 2nd line of the test's insertAndCheck method:




Code:
        dao.insertClient( c );       
        Client c2 = dao.getClient( c.getUCN() );



When I drill down into our HibernateDAO.listQuery method, I see that the IndexOutOfBoundsException is occurring when setParameter is called:



Code:
            for (int i = 0; i < params.length; i++) {
                  q.setParameter(i, params[i]);
            }



There is one parameter in the params array. Since there is a lot of debate in forums online about whether Query.setParameter is 0 or 1-based, I tried this and get the same exception:

Code:
            for (int i = 0; i < params.length; i++) {
                  int indexToSet = i + 1;
                  q.setParameter(indexToSet, params[i]);
            }


By the way, insert does work, and I see new rows in the database, so the problem is just occurring when we're having Hibernate retrieve the new record. It seems like the exception message doesn't really relate to whatever is causing the problem. Any ideas? Thanks so much...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 1:14 pm 
Newbie

Joined: Wed Aug 27, 2008 11:40 am
Posts: 2
It seems that Hibernate was getting confused with the superclass Client, so we casted the return object from getClient to the appropriate subclass of Client and it now works without any exception.


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