How do I catch the constraint violation exception from EclipseLink?

后端 未结 6 2402
-上瘾入骨i
-上瘾入骨i 2021-02-19 06:54

I am using EclipseLink in my web application, and I am having a hard time gracefully catching and handling Exceptions it generates. I see from this thread what seems to be a si

6条回答
  •  梦谈多话
    2021-02-19 07:19

    I use this.

    if (!ejbGuardia.findByPkCompuestaSiExiste(bean.getSipreTmpGuardiaPK())) {
        ejbGuardia.persist(bean);
        showMessage(ConstantesUtil.MENSAJE_RESPUESTA_CORRECTA, SEVERITY_INFO);
    } else {
        showMessage("Excel : El registro ya existe. (" + bean.toString() + ")  ", SEVERITY_ERROR);
    }
    

    and my function from above:

    public boolean findByPkCompuestaSiExiste(Object clasePkHija) throws ClassNotFoundException {
        if (null != em.find(this.clazz, clasePkHija)) {
            return true;
        }
        return false;
    }
    

    With that I dont need to program a validation for each Persist, its common in the my DAO Classes.

提交回复
热议问题