Expression of type List needs unchecked conversion to conform to List

3

I have a repository class that implements another method to obtain all my clients

@Repository
public class ClienteRepositoryImpl implements ClienteRepository{

    private EntityManager em;

    @Override
    @Transactional(readOnly = true)
    public List<ClienteEntity> findAll() {

        return em.createQuery("from Cliente").getResultList();

    }

}

The problem is that in the line of the return it throws me the following warning

  

Type safety: The expression of type List needs unchecked conversion to conform to List

I have searched in different places and it is not so clear to me because Java throws this at me. I have also read some questions on the subject in English such as this where it is even recommended to use the @SuppressWarnings (" unchecked ") tag as well as to disable the warnings that they can not be avoided, something that for me is bad practice.

How could I avoid this type of warning without the use of labels like the one mentioned?

    
asked by Lucas. D 22.02.2018 в 15:05
source

1 answer

3

You can try a TypedQuery :

return em.createQuery("from Cliente", ClienteEntity.class).getResultList();
    
answered by 22.02.2018 / 15:10
source