5 Replies Latest reply on Jun 17, 2009 6:19 PM by Fernando Montaño

    Can't catch exception caused by unique constraint?

    Andre Brandt Newbie

      Hi forum!

      I'm trying to write a small application for testing and learning...

      I've created an entity (useraccount) with a unique constraint on firstname. To test it, I wrote a small junit test which gets the reference via jndi lookup. Insert a new useraccount is no problem. So I tried to test the unique constraint. As it should, I get an exception if I try to persists a second, identical useraccount.

      But I'm not able to catch the exception.... I thought, that it would be a good idea, to throw some exeptions when for example an identical useraccount should be persist, but atm I don't know, how get this running...

      I also found this post: http://www.jboss.org/index.html?module=bb&op=viewtopic&t=71611&start=0&postdays=postDays&postorder=postOrder&highlight=highlight but I didn't figure out, what I've done wrong...


      Jboss 5.0.0.GA, ejb3

      best regards,
      Andre


      Exception in serverlog:

      19:11:47,775 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
      19:11:47,776 ERROR [JDBCExceptionReporter] Batch-Eintrag 0 insert into t_useraccount (version, disabled, personOfUserAccount, userlogin, userPassword, id) values (NULL, 0, NULL, foo, bar, 2) wurde abgebrochen. Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
      19:11:47,776 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 23505
      19:11:47,776 ERROR [JDBCExceptionReporter] FEHLER: doppelter Schluesselwert verletzt Unique-Constraint »t_useraccount_userlogin_key«
      19:11:47,776 ERROR [AbstractFlushingEventListener] 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)
      
      [.......]
      



      My SLSB:



       public Integer saveUserAccount(UserAccount userAccount) throws UserAccountAlreadyExistException {
      
       try {
       em.persist(userAccount);
       em.flush();
       return userAccount.getId();
       }
       catch (EntityExistsException eee) {
       throw new UserAccountAlreadyExistException();
       }
       catch (ConstraintViolationException e) {
       throw new UserAccountAlreadyExistException();
       }
      
       }
      


      UserAccountAlreadyExistException:
      @ApplicationException(rollback=true)
      public class UserAccountAlreadyExistException extends Exception {
      
       private static final long serialVersionUID = 1L;
      
       public UserAccountAlreadyExistException() {
       super();
       }
      
       public UserAccountAlreadyExistException(String s) {
       super(s);
       }
      }
      






        • 1. Re: Can't catch exception caused by unique constraint?
          Fernando Montaño Expert

          Did you find some solution to this problem?
          I had my application working pretty fine catching a EntityExistsException and throwing my own @ApplicationException exception in JBoss 4.2.3.

          Now that I upgraded to JBoss 5.1, the same code does not work anymore, I'm unable to catch neither EntityExistsException or ConstraintViolationException.

          Do you (or somebody else) know what can I do? I would really like to use JBoss 5 instead 4.2.3, but this problem is annoying me.

          Please help!

          • 2. Re: Can't catch exception caused by unique constraint?
            jaikiran pai Master

            Remember that the actual SQL queries may be executed on transaction commit (i.e. after the control has moved out of your code) which means it's too late to catch such exceptions.

            But please post the code and the entire exception stacktrace so that we can ascertain that this is not a bug.

            • 3. Re: Can't catch exception caused by unique constraint?
              Fernando Montaño Expert

              In fact, I'm using a manual flushing, that's the reason it was working in JBoss 4.2.3.

              My service:

              @Stateless
              @Name("genericService")
              @AutoCreate
              public class GenericServiceBean implements GenericService {
              
              
               @In(value = "#{entityManager}")
               private EntityManager em;
              
               public void create(Object entity) throws EntryDuplicatedException {
               try {
               em.persist(entity);
               em.flush();
               } catch (EntityExistsException e) {
               throw new EntryDuplicatedException();
               }
               }
              

              In the above code the EntityManager is a Seam Manager Persistence Context, which has been initiated with flush type manual in an invoker bean. Notice that the same version of Seam is being used, so I discarted this could be a problem of Seam version.


              My EntryDuplicatedException:
              @ApplicationException(rollback = true)
              public class EntryDuplicatedException extends Exception {
              
              
               public EntryDuplicatedException() {
               }
              
               public EntryDuplicatedException(String message) {
               super(message);
               }
              
               public EntryDuplicatedException(Throwable cause) {
               super(cause);
               }
              }
              



              The exception thrown in JBoss 5.1.0, where the same above code does not work, I can't catch the exception:
              10:28:40,652 INFO [STDOUT] Hibernate: insert into PAIS (CODIGOAREA, ID_COMPANIA, NOMBRE, PREFIJO, VERSION, ID_PAIS) values (?, ?, ?, ?, ?, ?)
              10:28:40,655 WARN [JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
              10:28:40,656 ERROR [JDBCExceptionReporter] Duplicate entry 'Bolivia' for key 2
              10:28:40,656 ERROR [AbstractFlushingEventListener] 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 com.jatun.eos.framework.service.GenericServiceBean.create(GenericServiceBean.java:42)
               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.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
               at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
               at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:138)
               at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
               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.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
               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.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
               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.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:83)
               at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:70)
               at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:59)
               at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
               at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
               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.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
               at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_2120900821.invoke(InvocationContextInterceptor_z_fillMethod_2120900821.java)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
               at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_2120900821.invoke(InvocationContextInterceptor_z_setup_2120900821.java)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
               at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:176)
               at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:216)
               at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
               at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
               at $Proxy892.create(Unknown Source)
               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.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
               at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
               at org.javassist.tmp.java.lang.Object_$$_javassist_seam_15.create(Object_$$_javassist_seam_15.java)
               at com.jatun.eos.framework.action.GenericAction.create(GenericAction.java:83)
               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.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:56)
               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.jatun.eos.action.contacts.CountryAction_$$_javassist_seam_14.create(CountryAction_$$_javassist_seam_14.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 javax.faces.component.UICommand.broadcast(UICommand.java:387)
               at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
               at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
               at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
               at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
               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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
               at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
               at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
               at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
               at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)
               at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)
               at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
               at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
               at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:406)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               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.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
               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.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:619)
              Caused by: java.sql.BatchUpdateException: Duplicate entry 'Bolivia' for key 2
               at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1269)
               at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:955)
               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)
               ... 190 more
              10:28:40,667 ERROR [TxPolicy] javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
              10:28:40,682 ERROR [[Faces Servlet]] El Servlet.service() para servlet Faces Servlet lanzó una excepción
              java.sql.BatchUpdateException: Duplicate entry 'Bolivia' for key 2
               at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1269)
               at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:955)
               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)
               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 com.jatun.eos.framework.service.GenericServiceBean.create(GenericServiceBean.java:42)
               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.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
               at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
               at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:138)
               at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
               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.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
               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.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
               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.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:83)
               at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:70)
               at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:59)
               at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
               at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
               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.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
               at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_2120900821.invoke(InvocationContextInterceptor_z_fillMethod_2120900821.java)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
               at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_2120900821.invoke(InvocationContextInterceptor_z_setup_2120900821.java)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
               at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:176)
               at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:216)
               at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
               at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
               at $Proxy892.create(Unknown Source)
               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.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
               at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
               at org.javassist.tmp.java.lang.Object_$$_javassist_seam_15.create(Object_$$_javassist_seam_15.java)
               at com.jatun.eos.framework.action.GenericAction.create(GenericAction.java:83)
               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.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:56)
               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.jatun.eos.action.contacts.CountryAction_$$_javassist_seam_14.create(CountryAction_$$_javassist_seam_14.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 javax.faces.component.UICommand.broadcast(UICommand.java:387)
               at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
               at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
               at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
               at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
               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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
               at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
               at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
               at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
               at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)
               at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)
               at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
               at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
               at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:406)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               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.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
               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.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:619)
              



              Just for comparative purposes, the exception thrown in JBoss 4.2.3. Although the exception is thrown in the console, the above code works fine, so the exception can be caught in the session bean:
              10:37:28,187 INFO [STDOUT] Hibernate: insert into PAIS (NOMBRE, CODIGOAREA, PREFIJO, VERSION, ID_COMPANIA, ID_PAIS) values (?, ?, ?, ?, ?, ?)
              10:37:28,201 WARN [JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
              10:37:28,201 ERROR [JDBCExceptionReporter] Duplicate entry 'Bolivia' for key 2
              10:37:28,201 ERROR [AbstractFlushingEventListener] 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:71)
               at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
               at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
               at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
               at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
               at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
               at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
               at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
               at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:296)
               at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:92)
               at com.jatun.eos.framework.service.GenericServiceBean.create(GenericServiceBean.java:42)
               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.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
               at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
               at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
               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.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
               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.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
               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.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
               at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
               at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
               at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
               at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
               at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
               at $Proxy230.create(Unknown Source)
               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.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
               at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
               at org.javassist.tmp.java.lang.Object_$$_javassist_seam_15.create(Object_$$_javassist_seam_15.java)
               at com.jatun.eos.framework.action.GenericAction.create(GenericAction.java:83)
               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.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:56)
               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.jatun.eos.action.contacts.CountryAction_$$_javassist_seam_14.create(CountryAction_$$_javassist_seam_14.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 javax.faces.component.UICommand.broadcast(UICommand.java:387)
               at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
               at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
               at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
               at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
               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.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
               at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
               at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
               at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
               at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)
               at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)
               at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
               at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
               at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:406)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               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.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
               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.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:230)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
               at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
               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:157)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
               at java.lang.Thread.run(Thread.java:619)
              Caused by: java.sql.BatchUpdateException: Duplicate entry 'Bolivia' for key 2
               at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1257)
               at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)
               at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:774)
               at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
               at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
               ... 162 more
              




              • 4. Re: Can't catch exception caused by unique constraint?
                jaikiran pai Master

                This looks like a Hibernate EntityManager problem http://opensource.atlassian.com/projects/hibernate/browse/EJB-382. JBoss AS 5.1.0 GA ships with 3.4.0 GA version of Hibernate Entitymanager and the bug is reported against that version. Seems to be fixed in 3.4.1

                • 5. Re: Can't catch exception caused by unique constraint?
                  Fernando Montaño Expert

                   

                  "jaikiran" wrote:
                  This looks like a Hibernate EntityManager problem http://opensource.atlassian.com/projects/hibernate/browse/EJB-382. JBoss AS 5.1.0 GA ships with 3.4.0 GA version of Hibernate Entitymanager and the bug is reported against that version. Seems to be fixed in 3.4.1


                  Yes you're right, I changed the caught exception to PersistenceException and it works as expected. So I hope the next JBoss version can have this hibernate fix (of course if they release it).

                  Thanks for your help.