-->
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: Basic HQL Question
PostPosted: Thu Sep 01, 2005 1:42 pm 
Newbie

Joined: Mon Jun 13, 2005 2:39 pm
Posts: 7
Hi. I have a very basic HQL question. I've been trying to retrieve data from database by passing a variable but having a problem with it. I could retrieve data by passing actual value but I'm not sure how to pass the variable which is a primary key in the table and retrieve one row from the database. It's failing on the line "result3 = s.createQuery("select dailyhoroscope from DailyHoroscope dailyhoroscope where :testID = dailyhoroscope.id").list();" where I'd like to pass the variable 'testID' to get data from database. What exactly does "Not all named parameters have been set" mean? Any tips or advice would be appreciate it very much.


Hibernate version:3.0

Code between sessionFactory.openSession() and session.close():

Transaction tx = s.beginTransaction();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date date = new java.util.Date();

List result1 = null;
List result2 = null;
List result3 = null;
List result4 = null;
int testID = 3;
result1 = s.createQuery("from DailyHoroscope").list();// list all data
result2 = s.createQuery("select dailyhoroscope.date from DailyHoroscope as dailyhoroscope").list(); // list data column
result3 = s.createQuery("select dailyhoroscope from DailyHoroscope dailyhoroscope where :testID = dailyhoroscope.id").list();

s.flush();
tx.commit();

Full stack trace of any exception that occurs:

org.hibernate.QueryException: Not all named parameters have been set: [testID] [select dailyhoroscope from DailyHoroscope dailyhoroscope where :testID = dailyhoroscope.id]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:114)
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:101)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:70)
at com.adsmack.smacklet.horoscope.persistence.hibernateDAO.HibernateHoroscopeDAO.getHoroscope(HibernateHoroscopeDAO.java:66)
at com.adsmack.smacklet.horoscope.business.helpers.HoroscopeHelper.getHoroscope(HoroscopeHelper.java:25)
at com.adsmack.smacklet.horoscope.TestHoroscopeHelper.testgetHoroscope(TestHoroscopeHelper.java:31)
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 junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Name and version of the database: MySQL


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 1:54 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
not all named parameters being set means that you have not assigned a value to all of your variables in your query.

say for example your query is
from Foo f where f.title=:title and f.author=:author and f.date=:date

your query must set the attributes for all 3 of the named attributes. The named attributes are the ones with the colons (:) in front of them.

Code:
Query q = new Query("from Foo f where f.title=:title and f.author=:author and f.date=:date");
q.setParameter("title", "Superman");
q.setParameter("author","bob");
q.setParameter("date","11.5.09");
List result = q.list();


the above is an example of how you would set your named parameters


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 3:54 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Documentation: 11.4.1.4. Bind parameters
http://www.hibernate.org/hib_docs/v3/re ... parameters

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 7:51 am 
Newbie

Joined: Mon Jun 13, 2005 2:39 pm
Posts: 7
Thank you very much for those replies. I have now better understanding of how it works and I was able to retrieve data :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 7:51 am 
Newbie

Joined: Mon Jun 13, 2005 2:39 pm
Posts: 7
Thank you very much for those replies. I have now better understanding of how it works and I was able to retrieve data :)


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.