title: Error while committing the transaction
body: <p>Hello I have a problem with Hibernate while validating User form. Validation itself works , method adding User to database w/o validation works but combined together gives me javax.persistence.RollbackException: Error while committing the transaction. I cant find any solution.</p>
  
  <p>Here is my domain class:</p>
  
  <pre><code>@Entity
  public class User {
  
  @Id
  @GeneratedValue
  private long id ;
  
  
  @Pattern(regexp= "[a-zA-Z ]+", message="{pattern.user.name.validation}")
  private String name;
  
  @Size(min=5, message="{pattern.user.password.validation}")
  private String password;
  
  @Pattern(regexp="[a-zA-Z0-9.!#$%&amp;’*+=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)" , message="{pattern.user.email.validation}")
  @UserEmail
  private String email;
  
  @Pattern(regexp= "[a-zA-Z0-9./ ]{4,60}", message="{pattern.user.address.validation}")
  private String address;
  
  @Pattern(regexp="[0-9-]{7,14}" , message="{pattern.user.tele.validation}")
  private String telephone;
  
  @Pattern(regexp="[0-9-/]{8,10}" , message="{pattern.user.birth.validation}")
  private String birth;
  </code></pre>
  
  <p>Here is repository:</p>
  
  <pre><code>@Repository
  public class JpaUserRepository implements UserRepository {
  
  EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("myDB");
  
  public boolean checkEmail(String email) {
  
      EntityManager entityManager = entityManagerFactory.createEntityManager();
  
      javax.persistence.Query query = entityManager.createQuery("select name from User where email=:check");
  
      query.setParameter("check", email);
  
      String test = query.getResultList().toString();
  
      if (test.equalsIgnoreCase("[]")) {
  
          entityManager.close();
          return false;
  
      }
  
      else {
  
          entityManager.close();
          return true;
      }
  
  }
  
  
  public void createUser(User user) {
  
      EntityManager createManager =       entityManagerFactory.createEntityManager();
  
      createManager.getTransaction().begin();
  
      System.out.println(user);
  
      createManager.persist(user);
  
      createManager.getTransaction().commit();
  
      createManager.close();
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is validation interface:</p>
  
  <pre><code>public class UserEmailValidator implements ConstraintValidator&lt;UserEmail,String&gt;{
  
  @Autowired UserService userservice;
  
  public void initialize(UserEmail constraintAnnotation) {
  
  }
  
  
  public boolean isValid(String value, ConstraintValidatorContext context) {
  
  
  
      if(userservice.checkEmail(value)==false)
          {
              System.out.println("valid ok");
              return true;
          }
          System.out.println("valid not ok");
              return false;
  
  }}
  </code></pre>
  
  <p>and the Controller:</p>
  
  <pre><code>@Controller
  public class UserController {
  
  @Autowired
  private UserService userService;
  
  @RequestMapping(value = "/signup", method = RequestMethod.GET)
  public String signUp(Model model) {
      User newUser = new User();
      model.addAttribute("newUser", newUser);
  
      return "registration";
  }
  
  @RequestMapping(value = "/signup", method = RequestMethod.POST)
  public String signUpProcess(@ModelAttribute("newUser") @Valid User newUser,BindingResult result, Model model, 
          HttpServletRequest request) {
  
      if (result.hasErrors()) {
  
          return "registration";
      }
  
      userService.createUser(newUser);
  
      model.addAttribute("name", newUser.getName());
  
      return "accountSuccess";
  }}
  </code></pre>
  
  <p>Exception</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing   failed; nested exception is javax.persistence.RollbackException: Error while committing the transaction
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
  root cause
  
   javax.persistence.RollbackException: Error while committing the transaction
         org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:86)
     com.michal.carRental.repository.jpa.JpaUserRepository.createUser(JpaUserRepository.java:55)
  com.michal.carRental.service.jpa.JpaUserService.createUser(JpaUserService.java:25)
     com.michal.carRental.controller.UserController.signUpProcess(UserController.java:43)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  java.lang.reflect.Method.invoke(Unknown Source)
     org.springframework.web.method.support.InvocableHandlerMethod.invoke(Invocabl   eHandlerMethod.java:215)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForReques    t(InvocableHandlerMethod.java:132)
     org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
  org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
  root cause
  
     javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.
  org.hibernate.validator.internal.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:311)
  org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:180)
  org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:124)
  org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:86)
  org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:442)
  org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:387)
  org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:351)
  org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:303)
  org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:133)
  org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:114)
  org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:78)
  org.hibernate.action.internal.EntityInsertAction.preInsert(EntityInsertAction.java:205)
  org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:82)
  org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:447)
  org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:333)
  org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:335)
  org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
  org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1224)
  org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:464)
  org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2894)
  org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2270)
  org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
  org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
  org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
  org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:230)
  org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
  org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:61)
  com.michal.carRental.repository.jpa.JpaUserRepository.createUser(JpaUserRepository.java:55)
  com.michal.carRental.service.jpa.JpaUserService.createUser(JpaUserService.java:25)
  com.michal.carRental.controller.UserController.signUpProcess(UserController.java:43)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  java.lang.reflect.Method.invoke(Unknown Source)
  org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
  org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
  org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
  org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
   root cause
  
    java.lang.NullPointerException
  com.michal.carRental.validator.UserEmailValidator.isValid(UserEmailValidator.java:25)
  com.michal.carRental.validator.UserEmailValidator.isValid(UserEmailValidator.java:1)
  org.hibernate.validator.internal.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:308)
  org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:180)
  org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:124)
  org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:86)
  org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:442)
  org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:387)
  org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:351)
  org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:303)
  org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:133)
  org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:114)
  org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:78)
  org.hibernate.action.internal.EntityInsertAction.preInsert(EntityInsertAction.java:205)
  org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:82)
  org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:447)
  org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:333)
  org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:335)
  org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
  org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1224)
  org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:464)
  org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2894)
  org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2270)
  org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
  org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
  org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
  org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:230)
  org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
  org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:61)
  com.michal.carRental.repository.jpa.JpaUserRepository.createUser(JpaUserRepository.java:55)
  com.michal.carRental.service.jpa.JpaUserService.createUser(JpaUserService.java:25)
  com.michal.carRental.controller.UserController.signUpProcess(UserController.java:43)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  java.lang.reflect.Method.invoke(Unknown Source)
  org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
  org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
  org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
  org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>