I got this error when I use query.list(). I fix it by using query.iterate(); See codes below: String query = "select D " + " FROM com.choicehotels.jpa.domain.HotDealEntity D " + " INNER JOIN D.hotel H " + " LEFT JOIN D.themes TH " + " WHERE D.categoryID in (:ids) " + " AND (D.startDate <= :date OR D.startDate IS NULL) " + " AND (D.endDate >= :date OR D.endDate IS NULL) " + " AND D.hotel.live = 1 " + " AND D.live = 1 AND D.language = :language"; String resultQuery = query; Query q = session.createQuery(resultQuery);
q.setDate("date", new Date()); q.setParameter("language", language); q.setParameterList("ids", ids);
//doesn't work here; if only one record back, no problem. if many records back, I get hibernate "collection is not associated with any session" exception //q.setReadOnly(true).list();
q.setReadOnly(true); for(Iterator i = q.iterate(); i.hasNext();) { //fix here result.add(i.next()); }
|