Javax.validation.ConstraintViolationException: Bean Validation restrictions (s) violated during preUpdate validation

I get an annoying error message when I try to insert a new element into many relationships using JPA 2.0, SpringMvc 3.0.

I have a table with states and another with Persons. A person can be connected with many states and the state with many people. In this particular case, I have listOfStates and then a person, and I would like to insert these elements into my many of many relationships.

ManyToMany Relationship (in STATE 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) } ) 

The DAO code I'm calling from my controller

 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 works fine when I do not paste data from a web page. What am I doing wrong here? I already have some people and conditions in the database.

Full Stack Error Message:

 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. Thank you all in advance.

+4
source share
2 answers

Wow! got it! I had to change the validation mode in my persistence.xml from Auto to NONE , which basically tells the application that it does not use bean validation at all. The error messages have disappeared and my DAO is working fine.

+5
source

Exceptions indicate that the JSR 303 Bean Validation is being used , and Hibernate is configured (Persistence.xml) to check them before updating anything.

JSR 303 Bean Validation - These are annotations, such as:

  • javax.validation.constraints.NotNull
  • javax.validation.constraints.Size
+1
source

All Articles