modified to support Hibernate4