• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate createSQLQuery parameter substitution problem

 
Alex Serna
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?
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • 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
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic