Custom Statistics

Hibernate includes:

  • a Statistics interface (org.hibernate.stat.Statistics) and
  • a StatisticImplementor interface (org.hibernate.stat.spi.StatisticsImplementor) that extends the first interface, and
  • a StatisticImpl class (org.hibernate.stat.internal.StatisticsImpl) that implements StatisticsImplementor

If I want to use a custom implementation of the interface StatisticsImplementor, how can I get Hibernate to use instances of that class?

Is there some Factory I override to produce my customized StatisticImpl? Or some configuration field where I giveits fully qualified class name?

My goal is for Hibernate to use my custom class anywhere it would currently use the out-of-the-box StatisticImpl.


You want to actually provide Hibernate an instance that implements the the StatisticsFactory in the configuration under the key hibernate.stats.factory. By doing that, Hibernate will use your custom factory to create the statistics object rather than the default behavior of instantiating a StatisticsImpl.