В моем классе Dao есть следующий метод
public Collection<Files> findFilesByFolder(Collection<Integer> ids) {
if (ids.size() > 0) {
StringBuffer qbe = new StringBuffer("select f from Files f where f.folders.idFolders in ( :id )");
return super.list(qbe, "id", ids);
}
else {
return new ArrayList<Files>(0);
}
}
И когда я вызываю эту функцию, она возвращает java .lang.ClassCastException: java .util.Arrays $ ArrayList не может быть приведенным к java .lang.Integer исключение
, вот объявление list (). И я надеюсь, что hibernate обрабатывает коллекцию. Но не знаю, как это закончится в исключении приведения класса. Спасибо
protected Collection<T> list(StringBuffer qbe, Object... parameterMap) throws InfrastructureException {
return this.findByQuery(qbe.toString(), parameterMap);
}
@SuppressWarnings("unchecked")
public Collection<T> findByQuery(String qbe, Object... parameterMap) throws InfrastructureException {
return (Collection<T>) anonymousFindByQuery(qbe, parameterMap);
}
-------------------------------------------------------------------------------------------
public Collection<?> anonymousFindByQuery(String qbe, Object ...parameterMap)
throws InfrastructureException{
getSession();
try {
Query q = createQuery(qbe, parameterMap);
return q.list();
} //end try
catch (HibernateException ex) {
WLog.DAOLogger.error("HibernateException", ex);
throw new InfrastructureException(ex);
} //end
}
--------------------------------------------------------------------------------------
protected Query createQuery(String qbe, Object... parameterMap) throws InfrastructureException {
Session session = getSession();
Query q = session.createQuery(qbe);
String formattedQuery = String.format("%s ", qbe);
for (int i = 0; i < parameterMap.length; i = i + 2) {
//Put the data in easy to use forms.
Object key = parameterMap[i];
Object value = parameterMap[i + 1];
String formattedKey = String.format(":%s ", key);
if(value == null || formattedQuery.indexOf(formattedKey) == -1){
continue;
}
if(value instanceof ArrayList){
q.setParameterList(key.toString(), (Collection<?>)value);
}
else{
q.setParameter(key.toString(), value);
}
}
return q;
}