Assuming you can't change the source of EntityRoleName you're kind of stuck. There are circumstances where there's no avoiding unchecked warnings. You can put a cast like (Iterator) but you'll just get a slightly different warning. The compiler is telling you it can't guarantee that the Iterator returned by the openByQuery method actually produces EntityRoleName objects. Given that assigning to an ...