Created
April 18, 2023 10:58
-
-
Save schophil/f6e5284e3ec63509ce6888ece0a74f67 to your computer and use it in GitHub Desktop.
Jpa statistics logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.CustomLog; | |
import org.hibernate.Session; | |
import org.springframework.stereotype.Component; | |
import org.springframework.transaction.annotation.Transactional; | |
import javax.persistence.EntityManager; | |
import javax.persistence.PersistenceContext; | |
@Component | |
@CustomLog(topic = "JPA") | |
public class JpaStatisticsLogger { | |
@PersistenceContext | |
private EntityManager entityManager; | |
@Transactional | |
public void log() { | |
Session session = entityManager.unwrap(Session.class); | |
log.info("Entity count: {}",session.getStatistics().getEntityCount()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment