我似乎不能捕获约束违例异常,但我在日志中看到它.
实体
@Column(unique = true) private String email;
我想这样抓住它
try { memberDao.create(newMember); } catch (ConstraintViolationException e) { // }
– 它从来没有到达catch块.
当我使用
catch(异常e)
我抓到“javax.transaction.RollbackException:ARJUNA016053:无法提交事务”.
这是错误日志:
21:24:36,296 ERROR [org.jboss.ejb3.invocation] (http--127.0.0.1-8080-5) JBAS014134: EJB Invocation Failed on component MemberDAOImpl for method public abstract void pv243.peaktogether.dao.MemberDAOInt.create(pv243.peaktogether.model.Member): javax.ejb.EJBTransactionRolledbackException: Transaction rolled back at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleEndTransactionException(CMTTxInterceptor.java:115) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:95) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:232) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at pv243.peaktogether.dao.MemberDAOInt$$$view178.create(Unknown Source) [peaktogether-ejb-0.0.1-SNAPSHOT.jar:] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_17] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_17] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_17] at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_17] at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:111) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at pv243.peaktogether.dao.MemberDAOInt$-682821774$Proxy$_$$_Weld$Proxy$.create(MemberDAOInt$-682821774$Proxy$_$$_Weld$Proxy$.java) [peaktogether-ejb-0.0.1-SNAPSHOT.jar:] at pv243.peaktogether.web.controller.RegisterController.register(RegisterController.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_17] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_17] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_17] at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_17] at org.apache.el.parser.AstValue.invoke(AstValue.java:262) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) 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:315) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at pv243.peaktogether.filters.SecurityFilter.doFilter(SecurityFilter.java:48) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at pv243.peaktogether.filters.EncodingFilter.doFilter(EncodingFilter.java:20) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) 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:368) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_17] Caused by: javax.transaction.RollbackException: ARJUNA016053: Could not commit transaction. at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1177) at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:117) at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75) at org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:92) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] ... 75 more Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: ERROR: duplicate key value violates unique constraint "member_email_key" Detail: Key (email)=(email@test.com) already exists. at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.ejb.AbstractEntityManagerImpl$CallbackExceptionMapperImpl.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1481) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:109) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76) at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273) at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93) at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:164) at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165) ... 78 more Caused by: org.hibernate.exception.ConstraintViolationException: ERROR: duplicate key value violates unique constraint "member_email_key" Detail: Key (email)=(email@test.com) already exists. at org.hibernate.exception.internal.sqlStateConversionDelegate.convert(sqlStateConversionDelegate.java:128) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.exception.internal.StandardsqlExceptionConverter.convert(StandardsqlExceptionConverter.java:47) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.jdbc.spi.sqlExceptionHelper.convert(sqlExceptionHelper.java:125) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.jdbc.spi.sqlExceptionHelper.convert(sqlExceptionHelper.java:110) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at sun.proxy.$Proxy99.executeUpdate(Unknown Source) at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2849) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3290) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:80) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:272) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:264) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:186) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1081) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:315) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:104) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] ... 84 more Caused by: org.postgresql.util.PsqlException: ERROR: duplicate key value violates unique constraint "member_email_key" Detail: Key (email)=(email@test.com) already exists. at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157) [postgresql-8.4-701.jdbc4.jar:] at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886) [postgresql-8.4-701.jdbc4.jar:] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) [postgresql-8.4-701.jdbc4.jar:] at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555) [postgresql-8.4-701.jdbc4.jar:] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417) [postgresql-8.4-701.jdbc4.jar:] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:363) [postgresql-8.4-701.jdbc4.jar:] at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493) at sun.reflect.GeneratedMethodAccessor206.invoke(Unknown Source) [:1.7.0_17] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_17] at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_17] at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] ... 98 more
我究竟做错了什么 ?
UPDATE>>
我当前的代码是:
try { memberDao.create(newMember); } catch (EJBTransactionRolledbackException e) { log.info("Exception caught!! "+e.getCausedByException()); log.info("Exception caught!! "+e.getCause()); log.info("Exception caught!! "+e.getMessage()); StackTraceElement[] stack = e.getStackTrace(); for (int i = 0; i< stack.length; i++) { log.info(stack[i].toString()); } }
日志是
22:02:57,297 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) Exception caught!! javax.transaction.RollbackException: ARJUNA016053: Could not commit transaction. 22:02:57,298 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) Exception caught!! javax.transaction.RollbackException: ARJUNA016053: Could not commit transaction. 22:02:57,298 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) Exception caught!! Transaction rolled back 22:02:57,298 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ejb3.tx.CMTTxInterceptor.handleEndTransactionException(CMTTxInterceptor.java:115) 22:02:57,299 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:95) 22:02:57,299 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:232) 22:02:57,299 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) 22:02:57,300 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) 22:02:57,300 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) 22:02:57,300 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) 22:02:57,301 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) 22:02:57,301 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) 22:02:57,302 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) 22:02:57,302 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) 22:02:57,302 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) 22:02:57,303 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) 22:02:57,303 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) 22:02:57,304 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) 22:02:57,304 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) 22:02:57,304 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) 22:02:57,305 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) 22:02:57,305 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) 22:02:57,305 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) 22:02:57,306 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) pv243.peaktogether.dao.MemberDAOInt$$$view241.create(Unknown Source) 22:02:57,306 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 22:02:57,306 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 22:02:57,307 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 22:02:57,307 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) java.lang.reflect.Method.invoke(Method.java:601) 22:02:57,307 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264) 22:02:57,308 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) 22:02:57,308 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137) 22:02:57,308 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260) 22:02:57,309 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:111) 22:02:57,309 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56) 22:02:57,309 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105) 22:02:57,310 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) pv243.peaktogether.dao.MemberDAOInt$-682821774$Proxy$_$$_Weld$Proxy$.create(MemberDAOInt$-682821774$Proxy$_$$_Weld$Proxy$.java) 22:02:57,310 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) pv243.peaktogether.web.controller.RegisterController.register(RegisterController.java:98) 22:02:57,310 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 22:02:57,310 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 22:02:57,311 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 22:02:57,311 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) java.lang.reflect.Method.invoke(Method.java:601) 22:02:57,311 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.apache.el.parser.AstValue.invoke(AstValue.java:262) 22:02:57,312 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) 22:02:57,312 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39) 22:02:57,312 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) 22:02:57,313 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) 22:02:57,313 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) 22:02:57,313 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) 22:02:57,313 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) javax.faces.component.UICommand.broadcast(UICommand.java:315) 22:02:57,314 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) 22:02:57,314 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) 22:02:57,314 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 22:02:57,315 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 22:02:57,315 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 22:02:57,315 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 22:02:57,315 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) 22:02:57,316 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) 22:02:57,316 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) 22:02:57,317 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) 22:02:57,317 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) 22:02:57,317 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) pv243.peaktogether.filters.SecurityFilter.doFilter(SecurityFilter.java:48) 22:02:57,318 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) 22:02:57,318 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) pv243.peaktogether.filters.EncodingFilter.doFilter(EncodingFilter.java:20) 22:02:57,318 INFO [pv243.peaktogether.web.controller.RegisterController] (http--127.0.0.1-8080-6) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) 22:02:57,319 INFO [pv243.peaktogether.web.controller.RegisterController] (http-
环境:
Postgresql 9.2
JBoss AS 7.1.1
JPA 2.0
干杯,
OSIRIS
解决方法
它被包装在一个EJBTransactionRolledbackException中,所以你应该尝试捕获一个而不是ConstraintViolationException.
ConstraintViolationException首先由PersistenceException包装,然后由RollbackException包装,最后由EJBTransactionRolledbackException包装.
您应该调用异常的getCause()方法,直到遇到约束违例或为空,这表示该异常不是由于约束违规引起的.你可以尝试一下:
try { memberDao.create(newMember); } catch (EJBTransactionRolledbackException e) { Throwable t = e.getCause(); while ((t != null) && !(t instanceof ConstraintViolationException)) { t = t.getCause(); } if (t instanceof ConstraintViolationException) { // Here you're sure you have a ConstraintViolationException,you can handle it } }