Can you turn off log messages for certain query in Hibernate / EJB 3.0?
Is there a way to override the parameter "hibernate.show_sql" for just a single query?
Can you turn off log messages for certain query in Hibernate / EJB 3.0?
Is there a way to override the parameter "hibernate.show_sql" for just a single query?
From hibernate configuration, i don't think it's possible.
Hibernate gives you two way to log a query : via setting the hibernate parameter hibernate.show_sql to true or by setting the log category org.hibernate.SQL to DEBUG. Both way are independent, and if you use both, your queries will be logged twice.
I prefer to use the second way: it is far more flexible because you may change it at runtime via the jmx-console (if you use jboss, this is working out of the box).
And also, hibernate is using apache commons logging (with hibernate.show_sql, hibernate is just writing the request to System.out).
I think it is possible to provide a custom implementation of a Logger for a given category (i don't know how easy or hard it is, i've never done it). Then, you just have to provide the logic that will decide between logging the request or not in your Logger implementation.
If it's just a query, i.e. you don't need the results in session for other updates, you may be able to create a separate SessionFactory just for that query.