6

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
  • 10,922
  • 3
  • 30
  • 28
InvincibleCoder
  • 113
  • 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

10

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
  • 784
  • 4
  • 12
  • 29
4

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
  • 113
  • 7
0

Example:

 SQLQuery<String> sqlQuery = factory
        .select(stringTemplate)
        .from("table")
        .where(areaIdPath.eq(13L));

  sqlQuery.setUseLiterals(true);

  String sql = sqlQuery.getSQL().getSQL();

set UseLiterals = true, and then getSQL() will get generated sql which has parms.

  Set whether literals are used in SQL strings instead of parameter bindings (default: false)
 
  <p>Warning: When literals are used, prepared statement won't have any parameter bindings
  and also batch statements will only be simulated, but not executed as actual batch statements.</p>
xiaojie
  • 11
  • 2