2

We are facing an issue with an API that is consuming a bit of time. In the log, it's showing the delay with a query.

[INFO ] 2022-06-01 13:38:51.122 (DataBuilder.java:294) 
[DEBUG] 2022-06-01 13:38:52.927 (SqlStatementLogger.java:128) 100365241355070 -http-nio-8989-exec-230 - UPDATE USER_USAGE ....

This is the Repository method that has been invoked

@Transactional
@Modifying
@Query(value = "UPDATE USER_USAGE SET DAILY_COUNT = DAILY_COUNT + ?, WEEKLY_COUNT= WEEKLY_COUNT + ?,MONTHLY_COUNT= MONTHLY_COUNT + ?, "
            + " DAILY_USAGE = DAILY_USAGE + ?, WEEKLY_USAGE = WEEKLY_USAGE + ?, MONTHLY_USAGE = MONTHLY_USAGE + ? WHERE USER_ID = ? AND SERVICE_ID = ?", nativeQuery = true)
int updateUsage(int dailyc, int weeklyc, int monthlyc, double dailya, double weeklya, double monthlya, String userId, Integer service);

The time difference was more than one second, so we were wondering whether that query is being written into the log after or before executing it?

The database being used is Oracle.

Arun Sudhakaran
  • 2,167
  • 4
  • 27
  • 52
  • You can certainly check the JPA source code and answer this question yourself. Towards this end, it would help your question to include the actual Java code which is generating this update log. Other than this, a good +1 question to ask. – Tim Biegeleisen Jun 06 '22 at 09:42
  • But @TimBiegeleisen, we are using a native query, so will that come under JPA source code. I checked inside `SqlStatementLogger` (line : 128), the code is `LOG.debug( statement );`, but I can't say that this method is called after or before executing the query right? – Arun Sudhakaran Jun 06 '22 at 09:56
  • We also probably need to know what your database is. – Tim Biegeleisen Jun 06 '22 at 09:57
  • We are using Oracle. – Arun Sudhakaran Jun 06 '22 at 10:00
  • 1
    From [thorben-janssen.com/hibernate-slow-query-log](https://thorben-janssen.com/hibernate-slow-query-log/) it seems that the debug message is logged after the execution of the query. – dariosicily Jun 06 '22 at 17:52

0 Answers0