-->
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.  [ 4 posts ] 
Author Message
 Post subject: IllegalArgumentException - Parameter does not exist
PostPosted: Tue May 13, 2008 12:56 pm 
Newbie

Joined: Fri Apr 25, 2008 1:50 pm
Posts: 10
Hi,

I'm using Hibernate 3.2, and I'm getting a java.lang.IllegalArgumentException, while trying to set a Long parameter of a query.

I'm using UserTransaction API directly to control my transaction, so I'm not calling openSession() and session.close(). I'm assuming that the session is opened when I start the transaction and that it is closed when I commit or rollback the transaction.

The problem occurs when the line "query.setLong(...)" of the method selectByFolder (see code below) is executed. The method selectByFolder belongs to one of my DAO classes:

Code:
public List selectByFolder(Key folder) throws InfraException {
   List list = new ArrayList();
   final String voClassName = this.getVOClass().getName();
   Session session = hibernateUtil.currentSession();
   try {
      String hql = "select i from "
                    + voClassName + " as i where "
          + "i.folder.id = :id and i.deleted = 'false'";
      Query query = session.createQuery(hql);
      query.setLong("id", folder.getId().longValue());
      list = query.list();
      ...

   } catch (Exception e) {
      ...
   }
   return list;
}



Here is the full stackTrace of the exception I'm getting:



java.lang.IllegalArgumentException: Parameter id does not exist as a named parameter in
[select i from br.fapesp.tidia.ae.common.portfolio.commontypes.vo.PortfolioItemVO as i
where i.folder.id = :id and i.deleted = 'false']
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:349)
at org.hibernate.impl.AbstractQueryImpl.setLong(AbstractQueryImpl.java:594)
at br.fapesp.tidia.ae.infra.portfolio.db.impl.HibernateItemDAO.selectByFolder(HibernateItemDAO.java:179)
at br.fapesp.tidia.ae.elearning.portfolio.itemmgr.impl.ItemMgrComponent.calculateNewItemNumber(ItemMgrComponent.java:1125)
at br.fapesp.tidia.ae.elearning.portfolio.itemmgr.impl.ItemMgrComponent.createPortfolioItem(ItemMgrComponent.java:235)
at br.fapesp.tidia.ae.system.portfolio.portfolioSystem.impl.PortfolioSystemComponent.createPortfolioItem(PortfolioSystemComponent.java:388)
at br.fapesp.tidia.ae.presentation.portfolio.action.CreatePortfolioItemAction.createPortfolioItem(CreatePortfolioItemAction.java:189)
at br.fapesp.tidia.ae.presentation.portfolio.action.CreatePortfolioItemAction.execute(CreatePortfolioItemAction.java:136)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:595)
ERROR: Parameter id does not exist as a named parameter in [select i from br.fap
esp.tidia.ae.common.portfolio.commontypes.vo.PortfolioItemVO as i where i.folder
.id = :id and i.deleted = 'false'] (2008-05-13 13:14:02,406 http-8080-Processor2
3_root)



Could anybody help me to undertsand what can be causing this exception?

Thanks in advance for any help,

Cristina


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 30, 2008 10:34 am 
Newbie

Joined: Mon Jun 30, 2008 10:29 am
Posts: 2
Did you find a resolution to this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 30, 2008 4:13 pm 
Newbie

Joined: Mon Jun 30, 2008 10:29 am
Posts: 2
I was able to fix my own problem. I had single quotes around my parameters. Hibernate just wants it plain. That is... :parameter NOT ':parameter'.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 01, 2008 5:16 am 
Newbie

Joined: Mon Jun 05, 2006 12:41 pm
Posts: 19
If you want your query to adapt to every SQL dialect, you should always parameterize all your request, even for " delete = 'false' "

I find strange in HQL to have SELECT clause.... i just never use it, i prefer bring whole object from the DB.


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