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....
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 ]
posted 14 years ago
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