Duplicando valor na lista com 27000 registros

3 respostas
pugnator

tenho uma consulta que retorna 27000 registros

tenho essa consulta em sql com nativeQuery, jpa 1.0 que esta duplicando numeros dentro da List que no SQL nao retornam…

algué já teve esse problema ?

Fiz um filtro com Set, mas dos 27000 retorna apenas 4500, se uso um LIMIT 10000 na consulta retorna os mesmos 4500 …

3 Respostas

A

Carinha, tem uma boa chance de isto ser algum problema relacionado a implantação do “equals” no seu bean.

Por exemplo, sua tabela retorna para cada registro 5 campos. Aí o seu equals só considera 4. Se você tiver 10 itens em que os 4 campos considerados são iguais, mas o quinto for diferente, 9 destes itens não aparecerão do resultado.

Nota: isso estou puxando do meu conhecimento de Hibernate e Set, talvez com JPA seja diferente. Mas duvido…

pugnator

Fiz como abaixo.

os atributos estao iguais as colunas pq estou com pouco tempo pra escrever @column em tudo… :slight_smile:

/**
 * 
 */
package br.com.entity.integracao;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.EntityResult;
import javax.persistence.Id;
import javax.persistence.SqlResultSetMapping;

 

@SqlResultSetMapping(name = "Contrato", entities = { @EntityResult(entityClass = br.com.entity.integracao.Contrato.class) })
@Entity
public class Contrato implements Serializable {

	private static final long serialVersionUID = 1L;
	@Id
	private Long id_matricula;
	private Long id_contrato;
	private Integer versao;
	private Date data_vencimento;
	private Long id_cobranca;
	private Long id_registro;
	private String nosso_numero;
	private Long id_parcela;
	private Long id_cliente;
	private Double valor_parcela;
	private Date apropriacao;

	/**
	 * @return the id_matricula
	 */
	public Long getId_matricula() {
		return id_matricula;
	}

	/**
	 * @param id_matricula the id_matricula to set
	 */
	public void setId_matricula(Long id_matricula) {
		this.id_matricula = id_matricula;
	}

	/**
	 * @return the id_contrato
	 */
	public Long getId_contrato() {
		return id_contrato;
	}

	/**
	 * @param id_contrato the id_contrato to set
	 */
	public void setId_contrato(Long id_contrato) {
		this.id_contrato = id_contrato;
	}

	public Integer getVersao() {
		return versao;
	}

	public void setVersao(Integer versao) {
		this.versao = versao;
	}

	public Date getData_vencimento() {
		return data_vencimento;
	}

	public void setData_vencimento(Date data_vencimento) {
		this.data_vencimento = data_vencimento;
	}

	public Long getId_cobranca() {
		return id_cobranca;
	}

	public void setId_cobranca(Long id_cobranca) {
		this.id_cobranca = id_cobranca;
	}

	public Long getId_registro() {
		return id_registro;
	}

	public void setId_registro(Long id_registro) {
		this.id_registro = id_registro;
	}

	public String getNosso_numero() {
		return nosso_numero;
	}

	public void setNosso_numero(String nosso_numero) {
		this.nosso_numero = nosso_numero;
	}

	public Long getId_parcela() {
		return id_parcela;
	}

	public void setId_parcela(Long id_parcela) {
		this.id_parcela = id_parcela;
	}

	public Long getId_cliente() {
		return id_cliente;
	}

	public void setId_cliente(Long id_cliente) {
		this.id_cliente = id_cliente;
	}

	public Double getValor_parcela() {
		return valor_parcela;
	}

	public void setValor_parcela(Double valor_parcela) {
		this.valor_parcela = valor_parcela;
	}

	public Date getApropriacao() {
		return apropriacao;
	}

	public void setApropriacao(Date apropriacao) {
		this.apropriacao = apropriacao;
	}

	@Override
	public String toString() {

		String v = "\ngetApropriacao " + getApropriacao() + "\ngetData_vencimento " + getData_vencimento() + "\ngetId_cliente " + getId_cliente() + "\n getId_cobranca "
				+ getId_cobranca() + "\ngetId_contrato " + getId_contrato() + "\ngetId_matricula " + getId_matricula() + "\ngetId_parcela" + getId_parcela() + "\ngetId_registro "
				+ getId_registro() + "\ngetNosso_numero " + getNosso_numero() + "\ngetNosso_numero " + getNosso_numero() + "\ngetValor_parcela " + getValor_parcela()
				+ "\ngetVersao " + getVersao();

		return v;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((apropriacao == null) ? 0 : apropriacao.hashCode());
		result = prime * result + ((data_vencimento == null) ? 0 : data_vencimento.hashCode());
		result = prime * result + ((id_cliente == null) ? 0 : id_cliente.hashCode());
		result = prime * result + ((id_cobranca == null) ? 0 : id_cobranca.hashCode());
		result = prime * result + ((id_contrato == null) ? 0 : id_contrato.hashCode());
		result = prime * result + ((id_matricula == null) ? 0 : id_matricula.hashCode());
		result = prime * result + ((id_parcela == null) ? 0 : id_parcela.hashCode());
		result = prime * result + ((id_registro == null) ? 0 : id_registro.hashCode());
		result = prime * result + ((nosso_numero == null) ? 0 : nosso_numero.hashCode());
		result = prime * result + ((valor_parcela == null) ? 0 : valor_parcela.hashCode());
		result = prime * result + ((versao == null) ? 0 : versao.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Contrato other = (Contrato) obj;
		if (apropriacao == null) {
			if (other.apropriacao != null)
				return false;
		} else if (!apropriacao.equals(other.apropriacao))
			return false;
		if (data_vencimento == null) {
			if (other.data_vencimento != null)
				return false;
		} else if (!data_vencimento.equals(other.data_vencimento))
			return false;
		if (id_cliente == null) {
			if (other.id_cliente != null)
				return false;
		} else if (!id_cliente.equals(other.id_cliente))
			return false;
		if (id_cobranca == null) {
			if (other.id_cobranca != null)
				return false;
		} else if (!id_cobranca.equals(other.id_cobranca))
			return false;
		if (id_contrato == null) {
			if (other.id_contrato != null)
				return false;
		} else if (!id_contrato.equals(other.id_contrato))
			return false;
		if (id_matricula == null) {
			if (other.id_matricula != null)
				return false;
		} else if (!id_matricula.equals(other.id_matricula))
			return false;
		if (id_parcela == null) {
			if (other.id_parcela != null)
				return false;
		} else if (!id_parcela.equals(other.id_parcela))
			return false;
		if (id_registro == null) {
			if (other.id_registro != null)
				return false;
		} else if (!id_registro.equals(other.id_registro))
			return false;
		if (nosso_numero == null) {
			if (other.nosso_numero != null)
				return false;
		} else if (!nosso_numero.equals(other.nosso_numero))
			return false;
		if (valor_parcela == null) {
			if (other.valor_parcela != null)
				return false;
		} else if (!valor_parcela.equals(other.valor_parcela))
			return false;
		if (versao == null) {
			if (other.versao != null)
				return false;
		} else if (!versao.equals(other.versao))
			return false;
		return true;
	}

}
pugnator

mudei o id para um id composto e tiramos o order by por data (que se repetia) por um id(pk)

funcionou…

Criado 22 de janeiro de 2012
Ultima resposta 22 de jan. de 2012
Respostas 3
Participantes 2