Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes Hibernate createSQLQuery parameter substitution problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate createSQLQuery parameter substitution problem" Watch "Hibernate createSQLQuery parameter substitution problem" New topic
Author

Hibernate createSQLQuery parameter substitution problem

Alex Serna
Ranch Hand

Joined: Sep 18, 2009
Posts: 58
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

Joined: Mar 24, 2008
Posts: 3817

If you want to substitute the table name then construct the query with it outside and then pass it to the method.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Alex Serna
Ranch Hand

Joined: Sep 18, 2009
Posts: 58
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

Joined: Mar 24, 2008
Posts: 3817

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate createSQLQuery parameter substitution problem
 
Similar Threads
Can use validator classes within action's validation methods?
Struts2 java.lang.reflect.InvocationTargetException (Struts2 with Hibernate)
org.apache.jasper.JasperException
Null Pointer Exception
struts2 tile 2.2.0