• Post Reply Bookmark Topic Watch Topic
  • New Topic

what'a wrong woth my HQL query?????

 
sajjad ahmad
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI!
I am trying to get records from a table using following HQL query

Query q1 = HibernateUtil.currentSession().createQuery(
"from InventoryIssuance ii where ii.merchantRegistration=:mr and ii.takenBack like :tb");
q1.setParameter("mr", merchantRegistration);
q1.setParameter("tb", "N");
inventoryIssuanceList = q1.list();

but i get inventoryIssuanceList as null

according to data in table the conditions must meet,
while debugning i found merchnatRegistration as hibernate object (present in db),takenBack has also the desired value
so conditions are ok here in this query i must be missing somethignelse which i cannt figureout.....
please can anyone guide me what i am doing wrong here....
Also please tell me is there any plugin available for jbuilder to write and debug those HQL queries...
thanks in advance....
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all I would be suspicious of this:
Originally posted by sajjad ahmad:

In your query you use LIKE but the parameter doesn't use the pattern matching character "%". I suspect that the parameter should be "N%". When you are building the query with the Criteria API you don't use the pattern matching character because you specify it in a different way - however when you are using HQL I believe that you have to specify it. See 14.9. Expressions

Originally posted by sajjad ahmad:
Also please tell me is there any plugin available for jbuilder to write and debug those HQL queries...

Don't know about a plugin, but in the hibernate.cfg.xml you can set

or alternately in the hibernate.properties

to have the generated SQL sent to log4j. Then it�s a matter of configuring the log4.properties to redirect the output to the desired target. Here is the one that comes with the caveatemptor(h3) sample application that redirects everything to the console:

[ April 19, 2006: Message edited by: Peer Reynders ]
 
sajjad ahmad
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Peer Reynders!
Thanks for your detail response.....your tip rgarding printing generated sql statements will realy he;p me alot but i am still searching for that IDE which should give me the facilities to write and debug HQL queries directly like i am using plsqldeveloper for oracle to write complex queries and stored procedures and can directly test them from the provided test enviornment dont have to put them in code and after a long execution of pages find that required result.....
i think same should go with HQL(like SQL) ther must be same tools available (like plsql developer for sql) for HQL....I am searching for those as i would realy help to code faster and debug faster....
If anyone else knows about it then please tell me......
or if in the meantime i am abke to find that i will post it on this thread...
thanks once again
 
Yasir Qureshi
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peer,
Hibernate prints the prepared statement and one can not see the paramaeters that are binded, is there a way to see the query with paprameters.

Thanks
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is the hibernate console for eclipse. it lets you write and test HQL queries on the fly.

and as for the parameter bindings: just turn DEBUG level logging on for org.hibernate or at least org.hibernate.type.

there is also the p6spy tool which lets you see what queries are executed (inlcuding parameters)


pascal
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!