title: Validations pass but when merge() is called a validation error is thrown
body: <p>Sorry for asking here but I can't for the life of me understand what is going on. Been looking for answers all around the web for hours with no luck.</p>
  
  <p>I have a simple Quiz modelled in JPA, using <a href="http://www.vraptor.org/" rel="nofollow">VRaptor</a> (an MVC framework) running in a WildFly 10.0.0.Final server which uses Hibernate 5.0.7.Final. A Quiz have many Questions which have <strong>2-10</strong> Alternatives each.</p>
  
  <p>I'm currently implementing a method for users to add/remove Questions on a Quiz. Before calling <code>merge(quiz)</code> I run the validations to make sure everything is valid. It passes. I get no errors.</p>
  
  <p>Since there are no validation errors, I call <code>merge(quiz)</code> and finally I'm greeted with the following exception:</p>
  
  <pre><code>javax.validation.ConstraintViolationException: Validation failed for classes [game.Question] during persist time for groups [javax.validation.groups.Default, ]
  List of constraint violations:[
      ConstraintViolationImpl{interpolatedMessage='Cannot be empty', propertyPath=alternatives, rootBeanClass=class game.Question, messageTemplate='{org.hibernate.validator.constraints.NotEmpty.message}'}
  ]
  </code></pre>
  
  <p>[Edit] If I deliberately leave something blank it does show the validation error and doesn't try to <code>merge()</code>, so validations are being run as expected.</p>
  
  <p>I've checked the whole thing manually and there really are no errors. Used this "alternative" method to check and print validation errors:</p>
  
  <pre><code>private void val(final Object obj, final String s) {
      final ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
      final javax.validation.Validator validator = factory.getValidator();
      final Set&lt;ConstraintViolation&lt;Object&gt;&gt; constraintViolations = validator.validate(obj);
      for (final ConstraintViolation cv : constraintViolations) {
          log.info("-------------");
          log.info(s + " ValidatationConstraint: " + cv.getConstraintDescriptor().getAnnotation());
          log.info(s + " ValidatationConstraint: " + cv.getConstraintDescriptor());
          log.info(s + " ValidatationConstraint: " + cv.getMessageTemplate());
          log.info(s + " ValidatationConstraint: " + cv.getInvalidValue());
          log.info(s + " ValidatationConstraint: " + cv.getLeafBean());
          log.info(s + " ValidatationConstraint: " + cv.getRootBeanClass());
          log.info(s + " ValidatationConstraint: " + cv.getPropertyPath().toString());
          log.info(s + " ValidatationConstraint: " + cv.getMessage());
          log.info("-------------");
      }
  }
  </code></pre>
  
  <p>This is roughly what my add/remove Questions method do:</p>
  
  <pre><code>@Transactional
  public void updateQuestions(final String quizId, final List&lt;Question&gt; questions) {
      // Quizzes might have slugs (/quiz-name)
      final Quiz quiz = findQuizByIdString(quizId);
      if (quiz != null) {
          for (final Question question : questions) {
              question.setQuiz(quiz);
  
              if (question.getAlternatives() != null) {
                  for (final Alternative alt : question.getAlternatives()) {
                      alt.setQuestion(question);
                  }
              }
  
              if (question.getId() != null) {
                  final Question old = (Question) ps.createQuery("FROM Question WHERE id = :id AND quiz = :quiz").setParameter("id", question.getId()).setParameter("quiz", quiz).getSingleResult();
  
                  // Making sure the Question do belong to the this Quiz
                  if (old == null) {
                      question.setId(null);
                  }
              }
  
              if (question.getId() == null) {
                  // Set the new question up (who created, timestamp, etc.)
              }
          }
  
          quiz.setQuestions(questions);
  
          if (!validator.validate(quiz).hasErrors()) {
              try {
                  entityManager.merge(quiz);
              } catch (final Exception e) {
                  if (log.isErrorEnabled()) { log.error("Error while updating Quiz Questions", e); }
              }
          }
      }
      else {
          // Send an error to the user
      }
  }
  </code></pre>
  
  <p>And finally these are the (what I think) relevant parts of my entities:</p>
  
  <pre><code>@Entity
  public class Quiz {
      /* ... */
      @Valid // FYI: This just makes the validation cascade
      @OneToMany(mappedBy = "quiz", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
      private List&lt;Question&gt; questions;
      /* ... */
  }
  
  @Entity
  public class Question {
      /* ... */
      @Valid
      @NotEmpty
      @Size(min = 2, max = 10)
      @OneToMany(mappedBy = "question", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
      private List&lt;Alternative&gt; alternatives;
      /* ... */
  }
  
  @Entity
  public class Alternative {
      /* ... */
      @NotBlank
      @Size(max = 0xFF)
      @Column(length = 0xFF, nullable = false)
      private String text; // The only field that must be filled
      /* ... */
  }
  </code></pre>