Show sql generated by JPA / Hibernate

1

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

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

    
asked by anonymous 20.07.2017 / 18:38

1 answer

1

You can enable and disable SQL logging using the code below

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

... código ...

sqlLogger.setLevel(Level.OFF);
    
20.07.2017 / 18:52