Major refactoring of how hibernate is used.