0

I'm try with hibernate and their POJO, cast to my POJO but have classcastexception How can fix?

private void open() throws Exception {
    //private ArrayList<Curso> listaCursos = new ArrayList<Curso>();
    try {
        sf = NewHibernateUtil.getSessionFactory();
        se = sf.openSession();
        Query query = se.createQuery("FROM Curso");

        System.out.println(listaCursos);
        List<Curso> lisst = new ArrayList<Curso>();
        for (Object c : query.list()) {
            listaCursos.add((Curso) c);
        }

    } catch (Exception e) {
        System.out.println(e);
    }
}

And see error log:

java.lang.ClassCastException: modelo.DAO.HIBERNATE.POJO.Curso cannot be cast to POJO.Curso
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • 2
    Well, the message speaks for itself: you're querying instances of the entity modelo.DAO.HIBERNATE.POJO.Curso, so you get a list containing instances of modelo.DAO.HIBERNATE.POJO.Curso, and you're trying to cast those objects to POJO.Curso. – JB Nizet Feb 17 '16 at 19:23
  • List refers to a list of POJO.Curso and your query is returning a list of modelo.DAO.HIBERNATE.POJO.Curso. Correct your imports. – andrucz Feb 17 '16 at 19:23

0 Answers0