Note that there are some explanatory texts on larger screens.

plurals
  1. POjavax.validation.ConstraintViolationException: Bean Validation constraint(s) violated on preUpdate validation
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p><strong>ManyToMany Relationship (in table STATE)</strong></p> <pre><code> //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) } ) </code></pre> <p><strong>DAO Code THAT I'm calling from my controller</strong></p> <pre><code>try{ getEntityManager().getTransaction().begin(); getEntityManager().persist(myPerson); IStateDAO stateDAO = new StateDAO(); for (int i=0; i&lt;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; } </code></pre> <p>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.</p> <p><strong>Full Stack Error Message:</strong></p> <pre><code>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. </code></pre> <p>Any pointer would be really appreciated. Thanks in advance you all.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload