fix hibernate transaction issue. refactor code