Psqlexception: ERROR: target lists can have a maximum of 1664 entries

Asked

Viewed 142 times

1

I am trying to persist an object in the database but I get this error:

WARN:   SQL Error: 0, SQLState: 54000
ERROR:   ERRO: listas de alvos podem ter no máximo 1664 entradas
Advertência:   A system exception occurred during an invocation on EJB OrdemServicoFacade, method: public void br.com.curso.ejb.OrdemServicoFacade.salvar(br.com.curso.entidade.OrdemServico)

My Way Save

     @Override
    public void salvar(OrdemServico entity) {

        if (entity.getVenda().equals(false)) {

            entity = em.merge(entity);

        } else if (entity.getTipoDoc().equals("DINHEIRO")) {

            entity = em.merge(entity);

            geraContasReceber(entity);

        } else if (entity.getTipoDoc().equals("CHEQUE")) {
            entity = em.merge(entity);
            geraCheque(entity);
            if (entity.getEntrada().compareTo(BigDecimal.ZERO) == 1) {

                geraContasRecebidas(entity);

            }

        } else if (entity.getTipoDoc().equals("CARTÃO CRÉDITO")) {
            entity = em.merge(entity);
            geraCartaoCredito(entity);

            if (entity.getEntrada().compareTo(BigDecimal.ZERO) == 1) {

                geraContasRecebidas(entity);

            }
            //CONTROLE CARTÃO CREDITO
        } else if (entity.getTipoDoc().equals("CARTÃO DÉBITO")) {
            entity = em.merge(entity);
            geraCartaoDebito(entity);
            if (entity.getEntrada().compareTo(BigDecimal.ZERO) == 1) {

                geraContasRecebidas(entity);

            }
            //CONTROLE CARTÃO DÉBITO

        } else if (entity.getTipoDoc().equals("CREDIÁRIO")) {
            entity = em.merge(entity);
            geraContasReceber(entity);
            if (entity.getEntrada().compareTo(BigDecimal.ZERO) == 1) {

                geraContasRecebidas(entity);

            }
            //CONTROLE CARTÃO DÉBITO

        }
    }

My Entity (Attributes)

        private static final long serialVersionUID = 1L;
    @Id
//    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column
    private Long id;
    @Column
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dtVenda = new Date();
    @Column
    private String nomeFun;
    @Column
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataVencimento = new Date();
    @Column
    private BigDecimal total = BigDecimal.ZERO;
    @Column
    private BigDecimal entrada = BigDecimal.ZERO;
    @Column
    private BigDecimal valorHora = BigDecimal.ZERO;
    @Column
    private BigDecimal totalDesc = BigDecimal.ZERO;
    @Column
    private BigDecimal totalDescEn = BigDecimal.ZERO;
    @Column
    private BigDecimal totalHoras = BigDecimal.ZERO;
    @Column
    private BigDecimal acrescimo = BigDecimal.ZERO;
    @Column
    private BigDecimal desconto = BigDecimal.ZERO;
    @Column
    private BigDecimal valorDesconto = BigDecimal.ZERO;
    @Column
    private Boolean venda = Boolean.FALSE;
    @Column
    private String valida;
    private String recebido;
    private String recebido2;
    private String recebido3;
    @Column
    private String localServico = "INTERNO";
    @ManyToOne
    private Bandeira bandeira;
    @Column
    private String numeroDoc;
    @Column
    private String modelo;
    @Column
    private String veiculo;
    private String contato;
    private String veiculo2;
    private String veiculo3;
    private String placa;
    private String placa2;
    private String placa3;
    private String obsVeiculo;
    @Column(length = 800)
    private String solicitacaoCliente;
    @Column
    @CPF
    private String cpfNota;
    @Column
    private String cnpjNota;
    @Column
    private String numeroSerie;
    @Column
    private String numeroHorasMaquinas;
    @Column
    private String numeroSerieMotor;
    @Column
    private String numeroSerieTranmmissao;
    @Column
    private String tipoServico;
    @Column
    private String saiuDe;
    private String chegouEm;
    @Temporal(javax.persistence.TemporalType.TIME)
    private Date horaSaida = new Date();
    @Temporal(javax.persistence.TemporalType.TIME)
    private Date horaChegada = new Date();
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dtIn;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dtFim;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dtPrevisao;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date horaViagem;

    private BigDecimal inicioServico = BigDecimal.ZERO;
    @Column(length = 600)
    private String descricaoProblema;
    @Column(length = 800)
    private String solucaoProblema;
    private BigDecimal terminoServico = BigDecimal.ZERO;
    private BigDecimal horaDeTrabalho = BigDecimal.ZERO;
    private String idFrota;
    private String kmInicial;
    private String kmFinal;
    @Column
    @Min(value = 1)
    private Integer qtdParcela = 1;
    @Column
    private String tipoPagamento = "A VISTA";
    @Column(length = 600)
    private String obs = "".toUpperCase();
    private String obs2 = "".toUpperCase();
    private String obs3 = "".toUpperCase();
    private String tipoDoc;
    @Column
    private Boolean fiscal = Boolean.FALSE;
    @ManyToOne
    private Pessoa pessoa;
    @ManyToOne
    private Funcionario funcionario;
    @ManyToOne
    private TipoDeManutencao tipoDeManutencao;
    @ManyToOne
    private SituacaoOs situacaoOs;
    @Column(columnDefinition = "TEXT")
    private String xml;
    private Boolean naoTransmitida;
    @ManyToOne
    private Banco banco;
    private String modeloNota;
    @OneToMany(cascade = CascadeType.ALL,
            fetch = FetchType.LAZY, orphanRemoval = true,
            mappedBy = "ordemServico")
    private List<ItemServico> itensServicos = new ArrayList<>();
    @OneToMany(cascade = CascadeType.ALL,
            fetch = FetchType.LAZY, orphanRemoval = true,
            mappedBy = "ordemServico")
    private List<ItemEquipamentos> itensEquipamentos = new ArrayList<>();
    @OneToMany(cascade = CascadeType.ALL,
            fetch = FetchType.LAZY,
            mappedBy = "ordemServico",
            orphanRemoval = true)
    private List<Parcela> parcelas;
    @ManyToOne
    private Empresa empresa;

    @Column(length = 900)
    private String retornoFiscal;
    @Column
    private String codNfce;
    @Column
    private String chaveNfce;
    @Column
    private String chaveNfe;
    @Column
    private String codNfe;
    @Column
    private Boolean fiscalCancelado;
    @Column
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date dataCancelamentoFiscal;
    @Column
    private String situacaoConsulta;
    @Column
    private String statusAux;

1 answer

1


This error occurs because you are returning many columns at the same time and hitting the Postgresql limit itself.

This case is quite typical using Hibernate when we have an entity mapping abusing strategy EAGER, loading other entities along with it at each query of it. This can be fixed, mainly by configuring the mappings @OneToOne and @ManyToOne for LAZY:

@ManyToOne(fetch = FetchType.LAZY)
private Pessoa pessoa;

In theory it would even be possible to increase this limit of 1664 in Postgresql, but it seems that is not possible do this today and it would not be a good recommendation anyway.

  • Your answer solved my problem, just one observation, when we use LAZY on objects that appear in a list for example, we need to load it manually, more if it doesn’t appear in the list and just put @Manytoone(fetch = Fetchtype.LAZY) and all right. Thank you for the reply.

Browser other questions tagged

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