Show sql generated by JPA/Hibernate

Asked

Viewed 312 times

1

Is there any way to show SQL generated by JPA/Hibernate without enabling the property <property name="hibernate.show_sql" value="true"/>?

The difficulty is that I need to monitor only one query and, if I turn on the show_sql all queries will be logged into the console.

1 answer

1


You can enable and disable the SQL log using the code below

Logger sqlLogger = Logger.getLogger("org.hibernate.SQL");
sqlLogger.setLevel(Level.DEBUG);

... código ...

sqlLogger.setLevel(Level.OFF);
  • Perfect! Thank you ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.