What I am trying to do is to ask Hibernate to execute a native sql (not hsql) for me, like below.
select * from test where name = '123'
however, if I use setParameter as below:
Code:
String sql = "select * from test where name = ?";
SQLQuery query = getSession().createSQLQuery(sql);
query.setParameter(1, "123");
then exception occurs and complaint that:
table test is not mapped.
I understand that it's trying to find any java class mapped to test table, however, I just want it to be executed "exactly" as native sql like
Code:
String sql = "select * from test where name = '123'";
SQLQuery query = getSession().createSQLQuery(sql);
I just don't want to combine the parameter with the sql string and would like to let hibernate to set for me so that I don't need to encode any specific value according to the database.
Any people have idea how to achieve it?