javax.validation.ConstraintViolationException:preUpdate验证违反了Bean验证约束 [英] javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated on preUpdate validation

查看:126
本文介绍了javax.validation.ConstraintViolationException:preUpdate验证违反了Bean验证约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用JPA 2.0,SpringMvc 3.0以多对多关系插入新元素时,出现了令人讨厌的错误消息.

I'm having an annoying error message while trying to insert new element in a many to many relationship using JPA 2.0, SpringMvc 3.0.

我有一张桌子,上面有国家,另一张桌子上有人".一个人可以链接到许多州,一个州可以链接到许多人. 在这种情况下,我有一个listOfStates,然后是一个人,我想将这些元素插入我的多对多关系中.

I have a table with States and another one with Persons. A person can be linked to many states and a state to many persons. In this particular case, I have a listOfStates and then a person and I would like to insert those elements in my many to many relationships.

多对多关系(在表STATE中)

    //bi-directional many-to-many association to Appointment
    @ManyToMany(cascade=CascadeType.ALL)
    @JoinTable(
name="PERSON_STATE"
, joinColumns={
    @JoinColumn(name="PERSON_ID", nullable=false)
    }
, inverseJoinColumns={
    @JoinColumn(name="CODE_STATE", nullable=false)
    }
)

我从控制器调用的DAO代码

try{    
    getEntityManager().getTransaction().begin();            
    getEntityManager().persist(myPerson);                       

    IStateDAO stateDAO = new StateDAO();

    for (int i=0; i<listOfStates.length; i++){
        State myState = stateDAO.findState(listOfStates[i]);
        if (myState != null){                   
            myState.getPersons().add(myPerson);
            getEntityManager().persist(myState);
        }
    }

    getEntityManager().getTransaction().commit();           
    getEntityManager().close();         

} catch (RuntimeException re) {
    getEntityManager().close();
    throw re;           
}

有趣的是,当我不从网页中插入数据时,此代码可以正常工作.我在这里做错了什么?数据库中已经有一些人和州了.

The funny thing is that this code is working fine when I'm not inserting data from a web page. What i am doing wrong here? I already have some persons and states in the DB.

完整堆栈错误消息:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'preUpdate'. Please refer to embedded ConstraintViolations for details.


javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'preUpdate'. Please refer to embedded ConstraintViolations for details.

任何指针将不胜感激.预先谢谢大家.

Any pointer would be really appreciated. Thanks in advance you all.

推荐答案

哇!知道了!我不得不将persistence.xml中的 validation-mode 从自动更改为 NONE ,这基本上告诉应用程序根本不使用Bean验证.错误消息消失了,我的DAO正常工作了.

wow! got it! I had to change the validation-mode in my persistence.xml from Auto to NONE which basically tells the app not to used the bean validation at all. Error messages are gone and my DAO works well.

这篇关于javax.validation.ConstraintViolationException:preUpdate验证违反了Bean验证约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆