I have a NamedQuery that only brings certain columns, the problem is that in my method
public List<T> NewEncontarSqlArmado(Map parametros, Asignaturas asignatura) throws ConsultarException {
try {
Iterator it = parametros.entrySet().iterator();
String consulta = "";
String orden = "";
boolean all = false;
int maxResults = -1;
int firstResult = -1;
String tabla = entityClass.getSimpleName();
Map par = new HashMap();
while (it.hasNext()) {
Map.Entry e = (Map.Entry) it.next();
String clave = (String) e.getKey();
if (clave.contains(";consulta")) {
consulta = (String) e.getValue();
} else if (clave.contains(";inicial")) {
firstResult = (Integer) e.getValue();
all = true;
} else if (clave.contains(";orden")) {
orden = " order by " + (String) e.getValue();
} else if (clave.contains(";final")) {
all = true;
maxResults = (Integer) e.getValue();
} else {
par.put(clave, e.getValue());
}
}
javax.persistence.Query q = getEntityManager().createNamedQuery(consulta).setParameter("asignatura", asignatura);
it = par.entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry) it.next();
String clave = (String) e.getKey();
q.setParameter(clave, e.getValue());
}
if (all) {
q.setMaxResults(maxResults);
q.setFirstResult(firstResult);
}
return q.getResultList();
} catch (Exception e) {
throw new ConsultarException(entityClass.toString(), e);
}
}
I return everything in Object [] type instead of the class I'm using at that moment which would be "File" and when I take it on my list in the file bean, I get the error that it could not take the object type value in List because it needs to be type "File".
I hope it was clear with my details: / I appreciate your help in advance.
This is the named Query that I have
@NamedQuery(name = "Archivos.SinArchivo", query = "SELECT a.id, a.codigo, a.nombre, a.descripcion, a.tipo, a.asignatura, a.activo, a.userid, a.fecha, a.tipoarchivo, a.demo, a.filepath FROM Archivos a WHERE a.asignatura= :asignatura and a.activo=true")