What is the “proper” way to cast Hibernate Query.list() to List?

后端 未结 10 1656
梦谈多话
梦谈多话 2020-12-04 11:44

I\'m a newbie with Hibernate, and I\'m writing a simple method to return a list of objects matching a specific filter. List seemed a natural return t

10条回答
  •  [愿得一人]
    2020-12-04 12:36

    Only way that work for me was with an Iterator.

    Iterator iterator= query.list().iterator();
    Destination dest;
    ArrayList destinations= new ArrayList<>();
    Iterator iterator= query.list().iterator();
        while(iterator.hasNext()){
            Object[] tuple= (Object[]) iterator.next();
            dest= new Destination();
            dest.setId((String)tuple[0]);
            dest.setName((String)tuple[1]);
            dest.setLat((String)tuple[2]);
            dest.setLng((String)tuple[3]);
            destinations.add(dest);
        }
    

    With other methods that I found, I had cast problems

提交回复
热议问题