Is there a way to get the SQL query from a session.get(class name, id)
call? I saw this post earlier: How to get SQL from Hibernate Criteria API (*not* for logging) but it does not cover get queries.
Clarification: I am looking for an API method to get the query string, not from the query log. In other words I am asking if there is a method (like toSql
below) where instead of:
Foo foo = session.get(Foo.class, id);
I can say something like:
String sqlOrHql = session.get(Foo.class, id).toSql();
// execute sqlOrHql to get foo, either through hibernate or manually using JDBC