How to bring a List in a JPQL query with constructor

1

Good afternoon,

I am doing a jpql query to bring a VO (Value Object) with some information, one of which is a List . This list is in the opCambio object, however, it is returning this error:

Log:

[ERROR] - 01/04/2017 19:16:26 - RuntimeException on EJB call
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [br.com.domain.relatorios.iof.vo.RelatorioIOFOrdemDePagamentoOperacaoCambioVO] [SELECT NEW br.com.domain.relatorios.iof.vo.RelatorioIOFOrdemDePagamentoOperacaoCambioVO(lp, opCambio.id, opCambio.dataRegistro) FROM br.com.domain.ordempagamento.OrdemDePagamentoOperacaoCambio opCambio  JOIN FETCH opCambio.liquidacoesParciais WHERE opCambio.tipoOperacaoCambioOrdemPagamento = :pTipoOperacao  AND opCambio.empresa = :pEmpresa  AND opCambio.situacao in (:pSituacoes)  AND doc.principal = :pPrincipal  AND opCambio.tipoOperacaoCambioOrdemPagamento = :pTipo AND opCambio.tipoAquisicao = :pTipoAquisicaoOrdemDePagamento AND opCambio.dataPrevistaMoedaNacionalBoleto >= :pDataInicial AND opCambio.dataPrevistaMoedaNacionalBoleto < :pDataFinal AND taxa.iof != :pTaxa]

Inquiry:

StringBuffer jpqlClausulaFrom = new StringBuffer("SELECT NEW " + RelatorioIOFOrdemDePagamentoOperacaoCambioVO.class.getName());
    jpqlClausulaFrom.append("(opCambio.liquidacoesParciais, opCambio.id, opCambio.dataRegistro)");
    jpqlClausulaFrom.append(" FROM OrdemDePagamentoOperacaoCambio opCambio ");

Builder:

public RelatorioIOFOrdemDePagamentoOperacaoCambioVO(List<LiquidacaoParcialOrdemDePagamento> listaLiquidacoes, Long id, Date dataRegistroOperacao) {

Could anyone help me?

    
asked by anonymous 20.03.2017 / 17:31

1 answer

0

The problem is probably that in the JPQL query you specify a lp variable that is not mentioned in the JPQL query.

To fix, you can generate a new JOIN with the alias lp :

JOIN opCambio.liquidacoesParciais lp

And remove the:

JOIN FETCH opCambio.liquidacoesParciais

I do not see much sense in making a FETCH of it in opCambio if you do not return the entity opCambio in SELECT .

    
30.07.2018 / 17:55