Statistics is not enabled: Hibernate Statistics API access error
0 reputation · 20 Aug 2026, 09:24 UTC
Statistics is not enabled
The Hibernate ORM throws a org.hibernate.HibernateException with the message "Statistics is not enabled" when SessionFactory.getStatistics() is called while statistics collection is not explicitly activated. This behavior is documented in the Hibernate 5.x and 6.x APIs and is triggered only by accessing the statistics API, not by other runtime operations.
In practice, developers enable statistics by setting hibernate.generate_statistics=true in the configuration or by calling setStatisticsEnabled(true) programmatically. The trade‑off is clear: enabling statistics incurs additional overhead, which may be undesirable in high‑throughput production environments, whereas disabling it protects performance but prevents detailed diagnostic data.
Despite these known trade‑offs, the community has not reached consensus on whether statistics should be enabled by default. The unresolved decision remains: should Hibernate provide a sensible default that balances diagnostic value against performance cost, or should it continue to require explicit activation to avoid accidental overhead?
What factors should influence the default statistics setting across different deployment contexts? How can developers reliably determine whether statistics are currently enabled without triggering the exception? Should Hibernate expose a programmatic query to report the current statistics state?