Last active
October 13, 2017 14:42
-
-
Save thjanssen/180eb6b5ce5a5794059b to your computer and use it in GitHub Desktop.
How to activate Hibernate Statistics to analyze performance issues (http://www.thoughts-on-java.org/2015/03/how-to-activate-hibernate-statistics-to.html)
This file contains hidden or 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
for (int i=0; i<10; i++) { | |
Product p = new Product(); | |
p.setName("MyProduct"+i); | |
this.em.persist(p); | |
} | |
this.em.createQuery("Select p From Product p").getResultList(); |
This file contains hidden or 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
@Entity | |
public class Product implements Serializable | |
{ | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "id", updatable = false, nullable = false) | |
private Long id = null; | |
@Version | |
@Column(name = "version") | |
private int version = 0; | |
@Column | |
private String name; | |
... | |
} |
This file contains hidden or 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
2015-03-03 20:28:52,484 DEBUG [org.hibernate.stat.internal.ConcurrentStatisticsImpl] (default task-1) HHH000117: HQL: Select p From Product p, time: 0ms, rows: 10 | |
2015-03-03 20:28:52,484 INFO [org.hibernate.engine.internal.StatisticalLoggingSessionEventListener] (default task-1) Session Metrics { | |
8728028 nanoseconds spent acquiring 12 JDBC connections; | |
295527 nanoseconds spent releasing 12 JDBC connections; | |
12014439 nanoseconds spent preparing 21 JDBC statements; | |
5622686 nanoseconds spent executing 21 JDBC statements; | |
0 nanoseconds spent executing 0 JDBC batches; | |
0 nanoseconds spent performing 0 L2C puts; | |
0 nanoseconds spent performing 0 L2C hits; | |
0 nanoseconds spent performing 0 L2C misses; | |
403863 nanoseconds spent executing 1 flushes (flushing a total of 10 entities and 0 collections); | |
25529864 nanoseconds spent executing 1 partial-flushes (flushing a total of 10 entities and 10 collections) | |
} |
This file contains hidden or 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
<system-properties> | |
<property name="hibernate.generate_statistics" value="true"/> | |
</system-properties> | |
... | |
<profile> | |
<subsystem xmlns="urn:jboss:domain:logging:2.0"> | |
... | |
<logger category="org.hibernate.stat"> | |
<level name="DEBUG"/> | |
</logger> | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment