-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Error with a search
PostPosted: Wed Nov 02, 2005 9:08 pm 
Newbie

Joined: Thu Oct 20, 2005 8:30 am
Posts: 10
Hello to all, I'm trying to do a search using this script:
Code:
Session sessao = (Session) HibernateUtil.sessionFactory.openSession();
      Criteria criteria = sessao.createCriteria(Gato.class);
      criteria.add(Restrictions.like ("nome", "%b%"));
      criteria.setMaxResults(5);
      List cats = (List) criteria.list();
      for (Iterator it = ((java.util.List) cats).iterator(); it.hasNext();){
         Gato gato = (Gato) it.next();
         System.out.println(gato.getNome());
      }
      
      sessao.close();

At least, I thought there would be no problem, but it's returning this error:
Code:
22:58:08,811Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList
   at teste.movimentos.GatoAcao.main(GatoAcao.java:131)



Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 9:17 pm 
Newbie

Joined: Thu Oct 20, 2005 8:30 am
Posts: 10
I resolved the problem. I only changed for this:
Code:
ArrayList cats =  (ArrayList) criteria.list();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.