Change from hibernate session to entitymanager and fix the queries and tests to work with it