Fixed a jpa query that hung the db