• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Hibernate createSQLQuery parameter substitution problem

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm having trouble with parameter substitution in Hibernate.

I'm using Hibernate 3.6.4-FINAL, Oracle Database 10g Express and the ojdbc14.jar driver.

When I execute this code:



I get the following exception. I have tried with setParameter("viewA", "empleados) and with positional parameter and none work. The query will succeed if I manually replace the select string and I don't use parameters.



From the log, it's like if Hibernate was trying to execute the query before the parameter substitution...

Any ideas?
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to substitute the table name then construct the query with it outside and then pass it to the method.
 
Alex Serna
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. That's what I ended up doing. I ended building the query string and avoiding parameter substitution.

I guess that in this case is fine because I'm not using any external input data and the view name is generated following some convention stuff.

I'm still curious why parameter substitution doesn't work in this case though....
 
Vijitha Kumara
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prepared statements are pre-compiled so that by just substituting the input parameters they should be able to run. But if it allowed to change the table name then this whole point is useless.
 
Liar, liar, pants on fire! refreshing plug:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic