I’m using Hibernate 3.3 in a Swing application. I’d like to retrieve some stats on the performed transaction and make that info available to my views. For example:
- Execution time
- Number of rows touched
- Type of transaction (update, delete, create, select etc)
I have several helper classes. I’m thinking of having some public fields like executionTime, noRows, transactionStatus etc and populate them in the finalize() method.
Does Hibernate provide a method to access this kind of data?
Yes, Hibernate provides live statistics. Usage example from the Hibernate book:
The statistics interfaces are
Statisticsfor global information,EntityStatisticsfor information about a particular entity,CollectionStatisticsfor a particular collection role,QueryStatisticsfor SQL and HQL queries, andSecondLevelCacheStatisticsfor detailed runtime information about a particular region in the optional second-level data cache. A convenient method islogSummary(), which prints out a complete summary to the console with a single call. If you want to enable the collection of statistics through the configuration, and not programmatically, set thehibernate.generate_statisticsconfiguration property to true. See the API documentation for more information about the various statistics retrieval methods.If you are running in an app server, you can also configure JMX to provide you statistics.