Improved the way of getting the entityManager and fix bug in AbstractDao