我這裏有春季引導休眠統計不工作?
https://github.com/jimbasilio/SpringBoot
一個小樣本的應用程序,在數據庫中創建一些簡單的數據和一些其他的事情我正在踢在春季啓動輪胎(邊注:到目前爲止,我愛春天開機!!)。如果克隆的混帳回購協議,您可以訪問網址:
http://127.0.0.1:8080/hello/get/1
,它會從數據庫中加載和寫休眠統計到控制檯。
我有一個問題,雖然,有或沒有通過application.properties文件配置Hibernate的統計:
hibernate.generate_statistics=true
當我寫休眠統計出來的我得到什麼有用的。我正在通過以下方式獲取統計信息:
Session session = (Session) this.entityManager.getDelegate();
session.getSessionFactory().getStatistics().logSummary();
HelloEntity entity = helloRepository.findOne(id);
entityManager.flush();
session.getSessionFactory().getStatistics().logSummary();
我的第二條日誌消息(沖洗之後)在下面。你可以看到它甚至沒有註冊正在打開的會話。我使用的是spring boot 1.0.1.RELEASE。
的pom.xml
日誌文件:
2014-04-28 20:51:29.415 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000161: Logging statistics....
2014-04-28 20:51:29.416 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000251: Start time: 1398732682476
2014-04-28 20:51:29.416 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000242: Sessions opened: 0
2014-04-28 20:51:29.416 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000241: Sessions closed: 0
2014-04-28 20:51:29.416 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000266: Transactions: 0
2014-04-28 20:51:29.416 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000258: Successful transactions: 0
2014-04-28 20:51:29.417 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000187: Optimistic lock failures: 0
2014-04-28 20:51:29.417 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000105: Flushes: 0
2014-04-28 20:51:29.417 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000048: Connections obtained: 0
2014-04-28 20:51:29.417 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000253: Statements prepared: 0
2014-04-28 20:51:29.417 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000252: Statements closed: 0
2014-04-28 20:51:29.417 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000239: Second level cache puts: 0
2014-04-28 20:51:29.418 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000237: Second level cache hits: 0
2014-04-28 20:51:29.418 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000238: Second level cache misses: 0
2014-04-28 20:51:29.418 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000079: Entities loaded: 0
2014-04-28 20:51:29.418 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000080: Entities updated: 0
2014-04-28 20:51:29.418 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000078: Entities inserted: 0
2014-04-28 20:51:29.418 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000076: Entities deleted: 0
2014-04-28 20:51:29.419 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000077: Entities fetched (minimize this): 0
2014-04-28 20:51:29.419 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000033: Collections loaded: 0
2014-04-28 20:51:29.419 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000036: Collections updated: 0
2014-04-28 20:51:29.419 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000035: Collections removed: 0
2014-04-28 20:51:29.419 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000034: Collections recreated: 0
2014-04-28 20:51:29.420 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000032: Collections fetched (minimize this): 0
2014-04-28 20:51:29.420 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000438: NaturalId cache puts: 0
2014-04-28 20:51:29.420 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000439: NaturalId cache hits: 0
2014-04-28 20:51:29.420 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000440: NaturalId cache misses: 0
2014-04-28 20:51:29.420 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000441: Max NaturalId query time: 0ms
2014-04-28 20:51:29.420 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000442: NaturalId queries executed to database: 0
2014-04-28 20:51:29.420 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000210: Queries executed to database: 0
2014-04-28 20:51:29.420 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000215: Query cache puts: 0
2014-04-28 20:51:29.421 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000433: update timestamps cache puts: 0
2014-04-28 20:51:29.421 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000434: update timestamps cache hits: 0
2014-04-28 20:51:29.421 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000435: update timestamps cache misses: 0
2014-04-28 20:51:29.421 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000213: Query cache hits: 0
2014-04-28 20:51:29.421 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000214: Query cache misses: 0
2014-04-28 20:51:29.421 INFO 18044 --- [nio-8080-exec-1] o.h.s.internal.ConcurrentStatisticsImpl : HHH000173: Max query time: 0ms
這是它!我有點震驚。我認爲所有的財產都合併在一起。謝謝您的回答! – JimB
事實證明,您可以爲本機JPA提供程序設置前綴並將其保留在application.properties中,但我在春季啓動文檔中忽略了這一點。所以在我的情況下,我添加了:spring.jpa.properties.hibernate.generate_statistics = true到我的application.properties文件,事情也起作用。我更喜歡這個文件到一個hibernate.properties文件,因爲我可以覆蓋dev/test/prod設置的application- {profile} .properties。再次感謝這一腳,它幫助。 – JimB