Database connection improvements

Opening and closing transactions in every database query. Hibernate
connection improvements.