Can I get the SQL string from a JPA Query object?

前端 未结 8 621
慢半拍i
慢半拍i 2021-01-01 12:36

May I know how can I get the sql from a JPA query? or let\'s say, convert the JPA query to a SQL string? Thank you very much!

8条回答
  •  天涯浪人
    2021-01-01 13:18

    Using Hibernate as a provider you can enable the following properties:

    hibernate.show_sql  
    

    Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL to debug. (e.g. true | false)

    hibernate.format_sql
    

    Pretty print the SQL in the log and console. (e.g. true | false)

    Or, as stated above you can enable logging to the debug level for the logger

    org.hibernate.SQL
    

    Log all SQL DML statements as they are executed

提交回复
热议问题