javax.validation.ConstraintViolationException:preUpdate验证违反了Bean验证约束

问题描述

| 尝试使用JPA 2.0,SpringMvc 3.0以多对多关系插入新元素时,出现了令人讨厌的错误消息。 我有一张与国家的桌子,另一张与人的桌子。一个人可以链接到许多州,一个州可以链接到许多人。 在这种情况下,我有一个listOfStates,然后是一个人,我想将这些元素插入我的多对多关系中。 ManyToMany关系(表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;           
}
有趣的是,当我不从网页插入数据时,此代码可以正常工作。我在这里做错了什么?我已经在数据库中有一些人和州。 全栈错误消息:
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.
任何指针将不胜感激。预先谢谢大家。     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)