I\'m using hibernate 4.2.6 and PostgreSQL 9.1
I\'ve been trying to execute sql query with hibernate. I\'ve written:
Session session
Another issue that might hit you (like it hit me) is this:
You want to run a native query, but can't get it to work in your production code? Pay attention if you are using a different database user for the application than the schema owner. In that case you may have to add the schema prefix to the referenced tables in order to make it work.
In my example I am using an entity manager instead of the session:
String sql = "select id from some_table";
Query query = em.createNativeQuery(sql);
List results = query.getResultList();
if some_table is owned by e.g. dba while the application is running as user, you will need to modify the query to:
String sql = "select id from dba.some_table";
Having Hibernate set to prefix all tables with
dba
does apparently NOT affect native queries.