title: javax.validation.ConstraintViolationException: validation failed for classes during persist time for groups [javax.validation.groups.Default, ]
body: <p>My entity has bean validation annotations <code>@NotBlank</code> and <code>@Size</code> on the <code>name</code> field. However, when I submit the JSF form with the <code>name</code> field left blank, it doesn't validate the field.</p>
  
  <p>Here's the field in question:</p>
  
  <pre><code>@NotBlank(message = "{name.required}")
  @Size(max = 25, message = "{long.value}")
  @Column(name = "name", length = 25, nullable = false)
  private String name;
  </code></pre>
  
  <p>When submitting the form without entering any data, I am getting the following exception:</p>
  
  <pre><code>Caused by: javax.faces.el.EvaluationException: javax.validation.ConstraintViolationException: validation failed for classes [com.myapp.domain.Department] during persist time for groups [javax.validation.groups.Default, ]
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      ... 89 more
  Caused by: javax.validation.ConstraintViolationException: validation failed for classes [com.myapp.domain.Department] during persist time for groups [javax.validation.groups.Default, ]
      at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:132)
      at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:71)
      at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:177)
      at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:72)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:260)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
      at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
      at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      at $Proxy212.addDepartment(Unknown Source)
      at com.myapp.beans.DepartmentBean.addOrUpdateDepartment(DepartmentBean.java:105)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
      at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
  </code></pre>
  
  <p>How is this caused and now can I solve it?</p>
  
  <hr>
  
  <p><strong>Update:</strong> here's the relevant part of the view:</p>
  
  <pre><code>&lt;h:form&gt;         
      &lt;ice:panelGrid columns="3"&gt;
          &lt;h:outputLabel&gt;Department Name:&lt;/h:outputLabel&gt;
          &lt;h:inputText id="name" value="#{departmentBean.departmentObj.name}" /&gt;
          &lt;h:message for="name" /&gt;
      &lt;/ice:panelGrid&gt;        
  &lt;/h:form&gt;
  &lt;h:form&gt;
      &lt;ice:panelGroup&gt;
          &lt;h:commandLink value="Add New" action="#{departmentBean.addOrUpdateDepartment}" /&gt;
      &lt;/ice:panelGroup&gt;
  &lt;/h:form&gt;
  </code></pre>