How to bring a List in a JPQL query with constructor

Asked

Viewed 237 times

1

Good afternoon,

I’m doing a jpql query to bring up a VO(Value Object) with some information, one of them being a List. This list is in the object opCambio, however, is returning me 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]

Consultation:

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 someone help me?

  • Put more codes so we can understand the problem, such as an excerpt from which instance this class.

  • Good morning, then, I’m trying to pass to a VO (Value Object) information coming from a query, one of this information is a list. The builder I passed up there, he’s in my VO class. In my query, I give a new one in my class and pass the fields I want to bring from the query to create the VO, in case, for the List, this returning me this error "Unable to locate appropriate constructor on class". The most relevant codes, are the ones I posted in doubt. I appreciate the help.

1 answer

0

The problem is probably that in the JPQL query you specify a variable lp which 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

'Cause I don’t see much point in making one FETCH of him in the opCambio if you do not return the entity opCambio in the SELECT.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.