Monday, 21 September 2009

Generics and getResultList()

So, this is a common problem with a dirty workaround.

If you try

public List<YourClass> getAllResults()
{
  return entityManager.createNamedQuery("YourClass.findAll").getResultList();
}

You get this:

found   : java.util.List
required: java.util.List<YourClass>
    return (List<YourClass>) entityManager.createNamedQuery("YourClass.findAll").getResultList();

or if you haven't compiled with -Xlint:unchecked, this Note: YourClass.java uses unchecked or unsafe operations.

The issue is described here

No comments:

Post a Comment