I have the following query:
SELECT datoUno(double), datoDos(double), datoTres(varchar)
FROM
Table_ejemplo
WHERE
dato_ID IN (164246, 164353,...);
My problem comes when from my implementing class for the data_ID parameters I pass a List like this: [164246, 164353, 123131,...].
This is the code:
private TransaccionResponse busquedaEjemplo(List<Integer> lstEjemplo) {
StringBuffer sql = new StringBuffer();
creaQueryEjemplo(sql);
SQLQuery query = db.createSQLQuery(sql.toString());
query.addScalar("datoUno", StandardBasicTypes.DOUBLE);
query.addScalar("datoDos", StandardBasicTypes.DOUBLE);
query.addScalar("datoTres", StandardBasicTypes.STRING);
query.setResultTransformer(
Transformers.aliasToBean(BeanReporteEjemplo.class));
query.setParameter("datoId",lstEjemplo);
List<BeanReporteEjemplo> resultados = query.list();
BeanReporteEjemplo= new ArrayList<BeanReporteEjemplo>();
for (Object object : resultados) {
BeanReporteEjemplo b = (BeanReporteEjemplo) object;
BeanReporteEjemplo.add(b);
}
return new SimpleTransaccionResponse(BeanReporteEjemplo);
}
BeanReportExample
private double datoUno;
private double datoDos;
private String datoTres;
public final static Campo PROP_DATO_UNO = new Campo("datoUno",
"dato Uno", double.class, 150, false, null,
new RendererSimple(Renderer.CENTER));
public final static Campo PROP_DATO_DOS = new Campo(
"datoDos", "dato Dos", double.class, 150, false,
null, new RendererSimple(Renderer.CENTER));
public final static Campo PROP_DATO_TRES = new Campo("datoTres", "dato Tres",
String.class, 150, false, null,
new RendererSimple(RendererSimple.CENTER));
public static List<Campo> getCampos() {
List<Campo> campos = new ArrayList<Campo>();
campos.add(PROP_DATO_UNO);
campos.add(PROP_DATO_DOS);
campos.add(PROP_DATO_TRES);
return campos;
}
getters() and Setters()....
It throws me the following error:
2019-11-01 09:53:06,642 WARN : SqlExceptionHelper - SQL Error: -4474, SQLState: null 2019-11-01 09:53:06,642 ERROR : SqlExceptionHelper - [jcc][1083][10406][3.66.46 ] Illegal conversion: can not convert from "byte[]" to "java.math.BigDecimal" ERRORCODE=-4474, SQLSTATE=null
The problem occurs when I pass a List: [164246, 164353, 123131,...] but when I perform a sub-query instead of passing the list, it does so without problem.
This way I don't get any errors.
SELECT datoUno(double), datoDos(double), datoTres(varchar)
FROM
Table_ejemplo
WHERE
dato_ID IN (SELECT
DISTINCT dato
FROM
tableExample
WHERE
datoEjemplo = 1142
AND datoEjemplo = 1);
I would be grateful if someone could guide me to solve this situation.
The solution of generating a sub-query instead of passing it the list worked for me up to a certain point, because not in all cases I can generate the sub-queries.
In the end I realized a very basic detail the truth. Well, I was passing a list of data as if it were a single parameter, like this:
The correct way to do it is as follows: