0 Replies Latest reply on Nov 9, 2009 10:47 AM by Oliver Libutzki

    Bean validation error

    Oliver Libutzki Newbie

      Hi everyone,


      I have a problem valiidating my entity bean.


      I have an entity bean (vcalled MyEntityBean) having two dates. I would like to validate these dates as date2 has to be after date1.


      I've written a custom hibernate validator (called MyValidator) doing this task for me. I've annotated my entity bean  like this:


      @Entity
      @MyValidator
      public class MyEntityBean
      



      In my ActionBean I've added an method which uses Seams Validators instance to validate my bean:


      public void validate(MyEntityBean aMyEntityBean)
      {
              ClassValidator<MyEntityBean> classValidator = Validators.instance().getValidator(MyEnttityBean.class);
              if (classValidator.hasValidationRules())
              {
                      for(InvalidValue invalidValue : classValidator.getInvalidValues(aMyEntityBean))
                      {
                              statusMessages.add( StatusMessage.Severity.ERROR, invalidValue.getMessage());
                      }
              }
      }
      



      The validation works, I get an error in the log if date2 is not after date1. But I also get thiis stacktrace. Looks like Seam commits my instance although it is invalid. What can I do to avoid this behaviour?


      java.lang.IllegalStateException: Could not commit transaction
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:625)
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:604)
              at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:345)
              at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:245)
              at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
              at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
              at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.persistence.RollbackException: Error while commiting the transaction
              at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
              at org.jboss.seam.transaction.EntityTransaction.commit(EntityTransaction.java:110)
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:613)
              ... 43 more
      Caused by: org.hibernate.validator.InvalidStateException: validation failed for: com.domain.MyEntityBean
              at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:148)
              at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:177)
              at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:237)
              at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:88)
              at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
              at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
              at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
              at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
              at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
              at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
              at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
              ... 45 more
      



      Thanks for your help!