0 Replies Latest reply on Jul 4, 2013 5:49 AM by heidi defense

    Q> This is all about Transaction Failed in Seam.

    heidi defense Newbie

      This is my Database Schema:

      Table name : ZTitles

      Cols:

          emp_no              int(11) PK NotNull

          title                  varchar(50) PK  NotNull

          from_date         date PK NotNull

          to_date                 date

       

       

       

       

       

      I've always getting this error message in my LOGS everytime I'm trying to create same values for emp_no, title, from_date which values are the same with the data stored (in the database).

       

      2013-07-04 17:30:55,114 WARN  [org.hibernate.util.JDBCExceptionReporter] (http-127.0.0.1-8080-3) SQL Error: 1062, SQLState: 23000

      2013-07-04 17:30:55,115 ERROR [org.hibernate.util.JDBCExceptionReporter] (http-127.0.0.1-8080-3) Duplicate entry '59987889-title-2013-07-16' for key 'PRIMARY'

      2013-07-04 17:30:55,115 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] (http-127.0.0.1-8080-3) Could not synchronize database state with session

      org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)

          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)

          at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)

          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)

          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)

          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.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:304)

          at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:92)

          at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:85)

          at com.icomteq.edd.master.action.ZTitlesHome.persist(ZTitlesHome.java:96)

          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.jboss.seam.util.Reflections.invoke(Reflections.java:22)

          at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)

          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)

          at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)

          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)

          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)

          at org.jboss.seam.util.Work.workInTransaction(Work.java:47)

          at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)

          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)

          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)

          at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)

          at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)

          at com.icomteq.edd.master.action.ZTitlesHome_$$_javassist_seam_47.persist(ZTitlesHome_$$_javassist_seam_47.java)

          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.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)

          at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)

          at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)

          at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)

          at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)

          at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)

          at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)

          at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)

          at org.primefaces.application.CleanupActionListener.processAction(CleanupActionListener.java:42)

          at javax.faces.component.UICommand.broadcast(UICommand.java:387)

          at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)

          at org.ajax4jsf.component.UIInclude.broadcast(UIInclude.java:170)

          at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:329)

          at org.ajax4jsf.component.AjaxViewRoot.broadcastEventsForPhase(AjaxViewRoot.java:304)

          at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:261)

          at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:474)

          at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)

          at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)

          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.LoggingFilter.doFilter(LoggingFilter.java:60)

          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)

          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)

          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.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:42)

          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)

          at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)

          at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)

          at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)

          at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)

          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.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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

          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:235)

          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)

          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)

          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)

          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)

          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)

          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

          at java.lang.Thread.run(Thread.java:662)

      Caused by: java.sql.BatchUpdateException: Duplicate entry '59987889-title-2013-07-16' for key 'PRIMARY'

          at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2024)

          at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1449)

          at com.mysql.jdbc.jdbc2.optional.StatementWrapper.executeBatch(StatementWrapper.java:721)

          at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:774)

          at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)

          at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)

          ... 100 more

      Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '59987889-title-2013-07-16' for key 'PRIMARY'

          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

          at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

          at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)

          at com.mysql.jdbc.Util.getInstance(Util.java:386)

          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1039)

          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)

          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)

          at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)

          at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)

          at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625)

          at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)

          at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2415)

          at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1976)

          ... 105 more

       

       

       

      Here is my Java Code for catching the error duplicate Entry:

      @Override

          public String persist() {

              String result = null;

              try {

                  result = super.persist();

          } catch (InvalidStateException e) {

              InvalidValue[] invalidValues = e.getInvalidValues();

              for (InvalidValue invalidValue : invalidValues) {

              log.info("Invalid Value property: #0", invalidValue.getPropertyName());

              log.info("Invalid Value: #0", invalidValue.getValue());

              }

              } catch(PersistenceException pex) {

                  result = "not-persisted";

                  String dup_e = "Duplicate entry";

                  String for_k = "for key";

                  String PK = "PRIMARY";

                  String entry = "";

                  boolean duplicateKey = false;

                  boolean duplicatePK = false;

                  Throwable t = pex.getCause();

                  while(t!=null) {

                      entry = t.getMessage();

                      t = t.getCause();

                      if ( entry.contains(dup_e)  && entry.contains(for_k) ) {

                          if ( entry.contains(PK) ) {

                              duplicatePK = true;

                          } else {

                              entry = entry.substring(entry.indexOf(for_k) + for_k.length());

                              entry = entry.replace((CharSequence)"UQ_",(CharSequence)"").trim();

                              duplicateKey = true;

                              break;

                          }

                      }

                  }

                  if (duplicateKey) {

                      FacesMessages.instance().add(FacesMessage.SEVERITY_INFO,"Duplicate entry for " + entry);

                  } else if (duplicatePK) {

                      FacesMessages.instance().add(FacesMessage.SEVERITY_INFO,"Duplicate Employee Number and Title combination");

                  }           

              } catch(Exception e) {

                  EddMasterLogCreator.createMasterLogRecord(e, this.getClass().getName(), "persist");

              }

              return result;

          }

       

       

       

       

      I've also tried to hide TransactionFailed Message.

       

      Any other Workaround there? on how to catch the Exception error, not to hide?

       

      Thanks ALL!