bug fixes and tested for Hibernate 4.2.2.Final