Using ArrayList<Object> in Hibernate Restrictions.in()

358 Views Asked by At

Restrictions.in(String propertyName,Collection values) work fine if an ArrayList of String or Integer or even simple array is passed to it.However I want to pass ArrayList of DTO object where DTO has a mapping file defined in hibernate.cfg.xml.

Here is the code for it:

Criteria  criteria  =session.createCriteria(MyDTO.class);
            criteria.add(Restrictions.in("reservationId",dtoList));
            assignments=(ArrayList<MyDTO>)criteria.list();

Here dtoList is ArrayList. I am getting a ClassCastException. Why doesn't this work when the mapping for the entity is known by Hibernate.

0

There are 0 best solutions below