【问题标题】:JPA query returning duplicated valuesJPA 查询返回重复值
【发布时间】:2013-06-24 16:38:10
【问题描述】:

我有一个应该返回 4 行的 jpa 查询,它确实返回了 4 行,但只有结果的前 2 行是可以的,接下来的 2 行是重复的第一行。不,第一行在数据库中没有重复。

这是我的查询:

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;

    }

我在做什么:

从一个名为“procesos”的视图中,我单击表中的任何“procesos”并转到其详细信息(将“proceso”ID 作为参数传递):

这是细节支持 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;
    }
}

如果我在查询中使用 distinct 它没有任何区别,我只得到 2 行,我确定在数据库中有 4 行具有相同的“id proceso”和不同的值。

【问题讨论】:

    标签: jpa jsf-2 jpa-2.0 openjpa


    【解决方案1】:

    我解决了它.. 这是因为我正在处理视图并且我没有为其中一个设置正确的 ID(我必须将 @Id 添加到实体的属性之一)

    【讨论】:

      猜你喜欢
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      • 2014-11-19
      • 2020-06-20
      • 2018-05-07
      • 1970-01-01
      • 2018-02-05
      • 2016-03-08
      相关资源
      最近更新 更多