Refactor hibernate