简体   繁体   中英

Spring data JPA logging

I want to log the time taken by the JPA repository to save the data into the database. Currently, I have used the Spring around Aspect to log it but it seems not so accurate because it doesn't commit until the end of @Transactional method.

@Timed(metricName = "inmtPersistence")
public void persistInmt(final List<T> inmtList) {

    if (inmtList.size() == 0) {
        return;
    }

    Map<String, E> inmtEntityMapFromDb = getInmtEntitiesFromDb(inmtList);

    List<E> inmtEntities = getInmtEntities(inmtList, inmtEntityMapFromDb);

    try {
        inmtRepository.saveAll(inmtEntities);
    } catch (Exception e) {
        log.error("Exception ");
        throw e;
    }

} 

您可以使用P6Spy ,它将注销所有单个查询的执行时间。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM