7

Any optimal way to show sql queries which are generated automatically while using querydsl of mysemma, so that these sql queries can be viewed easily and debugging of sql query becomes easy while working on querydsl.

For Example : from(qCustomer).where(qCustomer.custId.eq("1"));

I need to know the sql generated behind the scene and want to log so that I can debug my applications easily.

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
InvincibleCoder
  • 123
  • 1
  • 6
  • Have you tried to use hibernate configuration properties? http://stackoverflow.com/questions/2536829/hibernate-show-real-sql – Dmitry Senkovich Jan 04 '17 at 17:01
  • Yes Dmitry I have this property configured to true, but then also I am not able to see the sql generated. I am hoping if there is any way at java side or any property at mysemma querydsl side. – InvincibleCoder Jan 04 '17 at 17:10
  • There could be an issue with logger level. Please, have a look at the logger configuration on the link. – Dmitry Senkovich Jan 04 '17 at 17:11

3 Answers3

11

Spring boot users, add below to application.properties or equivalent yaml file to enable QueryDsl logs.

logging.level.com.querydsl.sql=DEBUG

Reference - AbstractSQLQuery's logQuery()

masT
  • 804
  • 4
  • 14
  • 29
5

Please add following setting in your application.properties file and check.

spring.jpa.show-sql=true

I am seeing the generated SQL using above setting. FYI, I am using Spring Data JPA and QueryDSL 4.1.3

Harshal
  • 123
  • 7
0

For those who want to do it in the code, by

String theSqlStr = theDslQuery.getSQL().getSQL();

you will get the generated sql

SebastianX
  • 142
  • 1
  • 5