Show JPA SQL statements when using Play Framework 2

I am developing a web application using the Play platform with JPA / Hibernate. For debugging purposes, it would be great to see the SQL statements used by JPA. There is already another thread there with the same question, but it is about Play 1, and this solution does not work for me - it seems that jpa.debugSQL=true cannot be used in Play 2 (a persistence provider for EntityManager named true) .

Instead, I added the following to play application.conf:

 db.default.logStatements=true logger.org.hibernate=DEBUG 

I'm not sure I need both rows, but at least SQL queries are being logged now. But for large queries, Hibernate prints a ton of debugging messages that cause already printed SQL statements to disappear in my console window. I already tried to increase the buffer of the console window, but this has not changed much.

What do I need to do to conveniently study applications?

edit:

When setting logger.org.hibernate to INFO I don't get any statements at all (even with db.default.logStatements=true ).

+6
source share
3 answers

Try first with configuration

 db.default.logStatements=true logger.org.hibernate=DEBUG 

Find out which class writes the statements (e.g. org.hibernate.xxx.StatementLogger). Go back to INFO for org.hibernate and add a new line for the logger statement package:

 logger.org.hibernate=INFO logger.org.hibernate.xxx=DEBUG 
+6
source

I used Hibernate with HikariCp, and the above proposed changes did not work for me. Instead, I used the hibernate property to reset sql, and it worked fine.

Add the following lines to the properties section of the persistence.xml file.

 <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hibernate.use_sql_comments" value="true"/> 
+2
source

Unfortunately, I don’t know how to do this in Hibernate, anyway, in Ebean you can enable and disable logging directly in ie code:

 Ebean.getServer(null).getAdminLogging().setDebugGeneratedSql(true); 

or

 Ebean.getServer(null).getAdminLogging().setDebugGeneratedSql(false); 

Otherwise, if Hibernate prints a ton of debugging messages , this may indicate the need to optimize your queries, that is, if you get a list of 100 records with lazy loaded relationships - ORM execute additional queries for missing data, and instead of a single query with a connection (- ami) it fulfills the n * relationship, so it can be a real performance killer .

0
source

All Articles