darrachequesne / spring-data-jpa-datatables

Spring Data JPA extension to work with the great jQuery plugin DataTables (https://datatables.net/)
Apache License 2.0
451 stars 172 forks source link

SqlExceptionHelper : No value specified for parameter 2 #86

Open ximBalaguer opened 6 years ago

ximBalaguer commented 6 years ago

Congratulations for your work. It's great.

I have a problem if I create a formula (@Formula) with parameters. In datatables, if I filter by the field linked to that formula, I get the following error:

Hibernate: select tercero0_.id as id13, tercero0_.apellidos as apellido23, tercero0_.fechaNacimiento as fechaNac33, tercero0_.nombre as nombre43, tercero0_.observaciones as observac53, tercero0_.persona as persona63, tercero0_.profesion as profesio73, tercero0_.salario as salario83, tercero0_.situacionId as situacio93, (SELECT GROUP_CONCAT(TD.denominacion) FROM trtercerosDirecc TD WHERE TD.terceroId = tercero0.id) as formula232, year(curdate())-year(tercero0.fechaNacimiento) as formula233_ from trterceros tercero0 left outer join tbnodos nodo1 on tercero0.situacionId=nodo1.id order by (SELECT TD.denominacion FROM tbnodosTraducs TD WHERE TD.nodoId = nodo1.id and TD.idiomaId = ?) asc limit ? 2018-09-21 08:38:35.309 WARN 7541 --- [nio-8081-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 07001 2018-09-21 08:38:35.309 ERROR 7541 --- [nio-8081-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : No value specified for parameter 2 retornar=DataTablesOutput(draw=2, recordsTotal=20, recordsFiltered=0, data=[], error=javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet)


CONTROLLER @JsonView(DataTablesOutput.View.class) @RequestMapping(value = "/findPaginados", method = RequestMethod.POST ) public @ResponseBody DataTablesOutput getTercerosPaginados(@Valid DataTablesInput input) { Session session = (Session) entityManager.unwrap(Session.class); session.enableFilter("filtroPorIdioma").setParameter("parIdioma", 12); DataTablesOutput retornar = agenda.findAll(input); return retornar; }


**MODEL***

@JsonView(DataTablesOutput.View.class)
@Formula("(SELECT TD.denominacion FROM tb_nodosTraducs TD WHERE TD.nodoId = id and TD.idiomaId = :filtroPorIdioma.parIdioma)")
private String denominacionTraducida;
darrachequesne commented 6 years ago

Hi! The @Formula annotation is not currently supported indeed.

I won't have time to take a look at it in the next few days, but I'll happily merge your fix if you find something :+1:

ximBalaguer commented 6 years ago

Thank you very much for your answer, Damien The @Formula works perfectly if it does not contain any parameters If in my formula I include a parameter then the problem appears

ximBalaguer commented 5 years ago

Hello Damien

Do you plan to implement this functionality in the future? I, feeling it a lot, do not have enough knowledge to do it. Thank you for your collaboration, Damien

ximBalaguer commented 5 years ago

Hello Damien

Do you plan to implement this functionality in the future? I, feeling it a lot, do not have enough knowledge to do it. Thank you for your collaboration, Damien

darrachequesne commented 4 years ago

@ximBalaguer no, I don't plan to implement it myself for now, as it is quite an uncommon use case. But as I said, if someone wants to implement it, I'll merge it :+1: