-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL query problem
PostPosted: Fri Jun 11, 2004 10:00 pm 
Newbie

Joined: Wed Feb 11, 2004 12:03 pm
Posts: 15
Hello, i'm trying to do a standard HQL query but I couldn't succeed...
I checked again and again the code and there is nothing different from the exemples i've read !
Could someone check and say what he thinks of it please ? ^^;

here is the code :

Code:
public List retrieveDataSets(String name) {   
      try {
      Session session = SessionManager.getSession();
      name="m12d.dat"; //test
      String query =
         "from datas.DataSet as ds "
         + "where ds.id = :name";
      System.out.println("name: " + name);
      System.out.println("query: " + query);
      List datasets = session.find(query);
      if (datasets.size() == 0) {
         System.out.println("No parameters named " + name);
         System.exit(0);
      }
      DataSet d = (DataSet) datasets.get(0);
      System.out.println("Found parameter: " + d);
      return datasets;
      
      } catch (HibernateException e) {
         throw new RuntimeException(e);
      }
   }

and the xml mapping og the bean
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
    <class name="datas.DataSet" table="DATASETS">
        <id name="id" type="string" unsaved-value="null">
         <column name="dataset_filename" sql-type="char(32)" not-null="true" />
         <generator class="assigned" />
      </id>
...
...
...
    </class>
</hibernate-mapping>


and the error :
Code:
name: m12d.dat
query: from datas.DataSet as ds where ds.id = :name
WARN  - SQL Error: 0, SQLState: 07001
ERROR - No value specified for parameter 1
WARN  - SQL Error: 0, SQLState: 07001
ERROR - No value specified for parameter 1
ERROR - Could not execute query
java.sql.SQLException: No value specified for parameter 1
   at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2201)
   at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2154)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1452)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:205)
   at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
   at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
   at net.sf.hibernate.loader.Loader.list(Loader.java:946)
   at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1536)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1505)
   at utils.DataSetManager.retrieveDataSets(DataSetManager.java:101)
   at actions.RetrieveAction.ListDataSets(RetrieveAction.java:111)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:309)
   at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:175)
   at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
   at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:182)
   at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:162)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at utils.SessionManager.doFilter(SessionManager.java:40)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
   at java.lang.Thread.run(Unknown Source)


I'm using hibernate 2, Webwork, tomcat and MySQL in my project


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 11, 2004 11:14 pm 
Newbie

Joined: Fri Jun 11, 2004 12:41 pm
Posts: 3
This part of the error message pretty much says it all:

ERROR - Could not execute query
java.sql.SQLException: No value specified for parameter 1

You need to bind a value to the param in your sql string (:name).

You can do this with session.find if you change the ":name" to a "?" and add 2 params to the call (the value to bind to the ? and the Hibernate type of the value you're providing):

// Revised line
List datasets = session.find(query,name,Hibernate.STRING);

Or if you prefer to use named params, you can use a Query object like this:

// Replace "List datasets ..." line with this
Query q = session.createQuery(query);
// bind an actual value to the :name param
q.setString("name", name);
List datasets = q.list();


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 13, 2004 2:11 am 
Newbie

Joined: Wed Feb 11, 2004 12:03 pm
Posts: 15
thanks you very much for your answer it work fine now :)


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