One way to debug Hibernate is to log the generated sql, another way is by enabling live statistics. By default ColdFusion has live statistics disabled and for good reason. This is not something you want running in production and its only meant for development. The easiest way to get statistics out of the Hibernate engine at runtime is the Session Factory. Fortunately for us ColdFusion has exposed this to us by using the ormGetSessionFactory() method.

If you run the following code you will see all of the different statistics methods exposed to you.

There are statistics for things like

  • Global Statistics
  • Entity Statistics for a particular entity
  • Collection Statistics for a particular collection role
  • Query Statistics for SQL & HQL queries
  • Second Level Cache Statistics for detail runtime information about a particular region in the optional second-level cache
If you try and call any of these methods right out of the gate they are not going to work. If you remember I said earlier that statistics are not enabled by default, but we can enable them pretty easily. Now when you call any of the stats methods we will start to see some data. There is also a continent method to find out if they are enabled.

Finally we could take this and add some debugging output to application by using the on request end method in our application. The hibernate_stats.cfm could have some output with any or all of the statistics methods.