Reputation: 1022
I have the following code on my Hibernate class:
public List<Something> getSomethingList(Integer[] ls){
String sql = "FROM SOMETHING WHERE IDSOMETHING IN (:ls)";
return this.getSession().createQuery(sql).setParameterList("ls", ls).list();
}
I Have an warning on the return line. The warning is the following:
Type safety: The expression of type List needs unchecked conversion to conform to List<Something>
I know this is not a big issue but how can I solve this warning?
Thanks
Upvotes: 0
Views: 414
Reputation: 93
Prevent Eclipse from generating warnings for unavoidable problems
In Eclipse, go to Window>Preferences>Java>Compiler>Errors/Warnings and under Generic type, select the checkbox
Ignore unavoidable generic type problems due to raw APIs
This will turn off unnecessary warnings for similar problems like the one described above which are unavoidable.
Upvotes: 0
Reputation: 18639
First Option: THIS:
List<Permission> permissions = Collections.checkedList(Permission.class, this.getSession().createQuery(sql).setParameterList("ls", ls).list());
Should be like this:
List<Permission> permissions = Collections.checkedList(this.getSession().createQuery(sql).setParameterList("ls", ls).list(),Permission.class);
Second Option:
Use:
@SuppressWarnings("unchecked")
Personally, I like the second option.
Upvotes: 1