Log that shows actual SQL query hibernate is executing?

Is there a log file that tells you the actual query hibernate is executing? We have a queryEntity that is behaving strangely and I want to run the same query on the DB to try to isolate the problem.

 

Thanks in advance!

Larson

  Discussion posts and replies are publicly visible

  •  To the best of my knowledge, it would require a configuration and in case if it's not yet done, the documentation at the following link should be of help to you:

    docs.appian.com/.../Customizing_Application_Logging.html

    Once when the above configuration is in place, I would check app server logs.

  • 0
    Certified Lead Developer

    You might want to do this on the database side, depending on the database type and how busy it is. You can normally switch on SQL trace, which stores every query that is run in a table, but it's quite resource-intensive and so should only be switched on for short periods.

    For what it's worth, a single a!queryEntity is usually made up of two or more SQL queries. If you've got sql trace on, you can search the results by the name of the table the query is running against.

  • 0
    Certified Lead Developer

    larsont i agree with sikhivahans , by following those steps mention in Link, can enable you to capture the actual query which gets prepared internally by Hibernate/JPA into logs, but however you will not be able to capture the data which will be forwarded for that Query Placeholders as it's Parameter.

    As we know that Hibernate/JPA generally uses PreparedStatement and making the use of placeholders(i.e. ?) and keep on sending the data to this query dynamically, so the log will capture the complete Query but without having Placeholder Data due to security purposes.

    e.g: select col1, col2, col3 from table where condition1=? and condition2=?;

    Generally in Hibernate, if you understand the risk, and still want to see the actual data along with the formed query (which you can directly copy from log and execute into DB without adding the data to the Query manually) then you can use P6Spy API which can capture the Actual query with it's data as well as the number of commits happened for a particular query (if applicable), but this requires as additional configuration, i am not sure do we have any way to configure Hibernate/JPA xml file which Appian uses internally, if yes, then for sure you will be able to capture each and every Query with it's data followed by it's commit statement.