user1462933
user1462933

Reputation: 1209

JPA query returning duplicated values

I have a jpa query that should return 4 rows, and it does return 4 rows, but only the first 2 rows of the result are ok, the next 2 are the first row repeated. And no, the first row is not repeated in the database.

this is my query:

public static List<DetalleProcesosEntity> getALLbyid(int id_proceso){
        Query q = entityManager.createQuery("select a from DetalleProcesosEntity a where a.idProceso=:id_proceso");
        q.setParameter("id_proceso", id_proceso);
        List<DetalleProcesosEntity>resultado=q.getResultList();
        List<DetalleProcesosEntity>result=new ArrayList<DetalleProcesosEntity>(resultado);
        return result;

    }

what im doing is:

from a view called "procesos" wich contains a table i click in any of the "procesos" in the table and i go to its details (passing the "proceso" ID as a parameter):

this is the details backing bean:

@ManagedBean(name = "det_procesos")
@ViewScoped
public class DetalleProcesosBean {

    private int idProceso;
    private List<DetalleProcesosEntity>detalles;
    @PostConstruct
    public void init(){
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        //Obtener parametros del request
        Map<String, String> parameterMap = externalContext.getRequestParameterMap();
        idProceso = Integer.parseInt(parameterMap.get("id_proc"));
        detalles= Procesos.getALLbyid(idProceso);
    }

    public List<DetalleProcesosEntity> getDetalles() {
        return detalles;

    }

    public void setDetalles(List<DetalleProcesosEntity> detalles) {
        this.detalles = detalles;
    }

    public int getIdProceso() {
       return idProceso;
    }



    public void setIdProceso(int idProceso) {
        this.idProceso = idProceso;
    }
}

if i use distinct in the query it does not make any difference, i just get 2 rows and im sure in the database there are 4 rows with the same "id proceso" and different values.

Upvotes: 0

Views: 1472

Answers (1)

user1462933
user1462933

Reputation: 1209

I solved it.. it was because i was working with views and i did not setted a proper ID to one of them (i had to add @Id to one of attributes of the entity)

Upvotes: 1

Related Questions