1 Reply Latest reply on Jan 18, 2008 12:03 PM by vikramchhetryy

    Iterate List of entities

    vikramchhetryy

      Hi all,
      I am getting class cast exception when I try to execute this code in this line
      roles = (Roles) it.next();

      public void loadRolesList() {
       List<Roles> list = (List<Roles>) em
       .createQuery(
       "select r.iroleId, r.strDescription from Roles r order by r.iroleId")
       .getResultList();
       log.info("Query executed = " + list.size());
       Roles roles;
       ListIterator<?> it = list.listIterator();
       while(it.hasNext()){
       roles = (Roles) it.next();
       log.info("Id = " + roles.getIroleId());
       rolesList.add(new SelectItem(roles.getIroleId(), roles
       .getStrDescription()));
       }
       }
      


      I am not sure if it is the right way of doing it but I want to iterate the list in java only.

      Any help would be appreciated.

      Thanks,
      Vikram

        • 1. Re: Iterate List of entities[FIXED]
          vikramchhetryy

          Problem fixed.
          I modified my code:

           public void loadRolesList() {
           Collection<Roles> list = em.createQuery(
           "select object(r) from Roles r order by r.iroleId")
           .getResultList();
          
           for (Roles roles : list) {
           rolesList.add(new SelectItem(roles.getIroleId(), roles
           .getStrDescription()));
           }
           }


          Thanks,
          Vikram