Changed sql query to HQL query