• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parameter not being set in HQL

 
Juzar Roopawalla
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method call:

project = ( Project_BC ) session.createQuery("from Project_BC where projectId =?").setLong( 0, longValue ).uniqueResult();

which throws the following exception:

Encountered exception while executing runInsert: org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter
.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:749)
at com.msdw.pbefficiency.servicestracker.dao.BussConsDAO.getProjectByProjId(Unknown Source)


And the cause of the problem is :
Caused by: java.sql.SQLException: JZ0SA: Prepared Statement: Input parameter not set, index: 1.

Why is this the cause of the problem when there is a setLong method has been used?
Also what is runInsert - mentioned at the beginning of the exception??
I am
Trying to meet a deadline so please let me know if you happen to have any pointers.
[ October 22, 2007: Message edited by: Mark Spritzler ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are Hibernate parameters 0 or 1 based indexes. It looks like it is 1 based, so change your "0" to "1", and try that out. I don't recall off the top of my head if this is the case, but why not check that out. It looks that way based on the exception you posted.

Mark
 
Juzar Roopawalla
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. They are 0 based. I had tried changing it to 1, it gives me the following exception:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Positional parameter does not exist: 1 in query: from Project_BC where projectId =?

btw... the strange thing is that it works from a program where the sessionfactory is created from a config file using a fixed path, where as I am creating it using JNDI. Don't think this should be of any consequence to the way hibernate executes the queries...but this is the only difference between the two programs. one works and one throws the above exception.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, The SessionFactory would still be configured whether it is in JNDI or not, I think the JNDI part is probably a red herring, but it is interesting that it works in one situation and not the other.

And Unfortunately, I am out of ideas.

Mark
 
Juzar Roopawalla
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We changed to named parameters and it worked, so we changed from :
Query q = session.createQuery("from Project_BC where projectId=?")
.setLong( 0, projId );

to

Query q = session.createQuery("from Project_BC where projectId= rjId")
.setLong( "prjId", projId );

We have changed all parameterized queries the same way.
Thanks Mark for looking into it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic