3

Eu estou usando o vraptor 4, JPA e Oracle.

Porém quando ocorre alguma exceção durante a persistência o código do erro que o Oracle gera não está vindo junto com a Exeption.

Esse é o Repository

 @Repository
public class AuthUserRepository {
    public void delete(AuthUser authUser) {
        em.remove(authUser);
        em.flush();
    }
}

E este é o serviço que chama o Repository

@Stateless
public class AuthUserServiceBean implements AuthUserServiceLocal {
@Override
    @PermitAll
    public void delete(Long userId) {
        try {
            AuthUser user = new AuthUser();
            user.setId(userId);
            authUserRepository.delete(user);
        } catch (Exception e) {
            e.getLocalizedMessage();
        }
    }
}

Quando é invocado o serviço para remover o AuthUser e ele possui algum relacionamento com outras tabelas o ORACLE gera o erro:

ORA-02292: restrição de integridade (FUNDAPLUB.FK_NOMM0XPXEU2DDLKL4I1DM3L98) violada - registro filho localizado

Esse é o printStackTrace

14:00:08,856 ERROR [stderr] (default task-1) java.lang.IllegalArgumentException: Removing a detached instance br.com.fundaplub.model.entity.AuthUser#62
14:00:08,856 ERROR [stderr] (default task-1)     at org.hibernate.jpa.event.internal.core.JpaDeleteEventListener.performDetachedEntityDeletionCheck(JpaDeleteEventListener.java:69)
14:00:08,857 ERROR [stderr] (default task-1)     at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:106)
14:00:08,857 ERROR [stderr] (default task-1)     at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:73)
14:00:08,857 ERROR [stderr] (default task-1)     at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:916)
14:00:08,857 ERROR [stderr] (default task-1)     at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:892)
14:00:08,857 ERROR [stderr] (default task-1)     at org.hibernate.jpa.spi.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:1214)
14:00:08,858 ERROR [stderr] (default task-1)     at org.jboss.as.jpa.container.AbstractEntityManager.remove(AbstractEntityManager.java:644)
14:00:08,858 ERROR [stderr] (default task-1)     at br.com.fundaplub.model.repository.AuthUserRepository.delete(AuthUserRepository.java:171)
14:00:08,858 ERROR [stderr] (default task-1)     at br.com.fundaplub.model.service.AuthUserServiceBean.delete(AuthUserServiceBean.java:131)
14:00:08,858 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:00:08,858 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
14:00:08,859 ERROR [stderr] (default task-1)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
14:00:08,859 ERROR [stderr] (default task-1)     at java.lang.reflect.Method.invoke(Unknown Source)
14:00:08,859 ERROR [stderr] (default task-1)     at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
14:00:08,859 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,859 ERROR [stderr] (default task-1)     at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
14:00:08,860 ERROR [stderr] (default task-1)     at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
14:00:08,860 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,860 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
14:00:08,860 ERROR [stderr] (default task-1)     at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)
14:00:08,860 ERROR [stderr] (default task-1)     at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)
14:00:08,861 ERROR [stderr] (default task-1)     at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
14:00:08,861 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,861 ERROR [stderr] (default task-1)     at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
14:00:08,861 ERROR [stderr] (default task-1)     at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
14:00:08,862 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,862 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)
14:00:08,862 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,862 ERROR [stderr] (default task-1)     at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
14:00:08,862 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,873 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
14:00:08,873 ERROR [stderr] (default task-1)     at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
14:00:08,874 ERROR [stderr] (default task-1)     at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
14:00:08,874 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,875 ERROR [stderr] (default task-1)     at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45
14:00:08,875 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,875 ERROR [stderr] (default task-1)     at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
14:00:08,876 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,876 ERROR [stderr] (default task-1)     at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
14:00:08,876 ERROR [stderr] (default task-1)     at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
14:00:08,877 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,877 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59)
14:00:08,877 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,878 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273)
14:00:08,878 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:340)
14:00:08,878 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239)
14:00:08,879 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,879 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
14:00:08,880 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,880 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43)
4:00:08,880 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,881 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.security.AuthorizationInterceptor.processInvocation(AuthorizationInterceptor.java:123)
14:00:08,881 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,881 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95)
14:00:08,882 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,882 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)
14:00:08,882 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,883 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
14:00:08,890 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,890 ERROR [stderr] (default task-1)     at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
14:00:08,891 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,891 ERROR [stderr] (default task-1)     at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55)
14:00:08,891 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,891 ERROR [stderr] (default task-1)     at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
14:00:08,892 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,892 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
14:00:08,892 ERROR [stderr] (default task-1)     at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:448)
14:00:08,892 ERROR [stderr] (default task-1)     at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
14:00:08,893 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,893 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
14:00:08,893 ERROR [stderr] (default task-1)     at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
14:00:08,893 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,893 ERROR [stderr] (default task-1)     at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
14:00:08,893 ERROR [stderr] (default task-1)     at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:185)
14:00:08,894 ERROR [stderr] (default task-1)     at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182)
14:00:08,894 ERROR [stderr] (default task-1)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
14:00:08,894 ERROR [stderr] (default task-1)     at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
14:00:08,894 ERROR [stderr] (default task-1)     at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:73)
14:00:08,894 ERROR [stderr] (default task-1)     at br.com.fundaplub.model.service.AuthUserServiceLocal$$$view8.delete(Unknown Source)
14:00:08,894 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:00:08,895 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
14:00:08,895 ERROR [stderr] (default task-1)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
14:00:08,895 ERROR [stderr] (default task-1)     at java.lang.reflect.Method.invoke(Unknown Source)
14:00:08,895 ERROR [stderr] (default task-1)     at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:401)
14:00:08,895 ERROR [stderr] (default task-1)     at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:99)
14:00:08,895 ERROR [stderr] (default task-1)     at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
14:00:08,896 ERROR [stderr] (default task-1)     at org.jboss.weld.bean.proxy.InjectionPointPropagatingEnterpriseTargetBeanInstance.invoke(InjectionPointPropagatingEnterpriseTargetBeanInstance.java:65)
14:00:08,896 ERROR [stderr] (default task-1)     at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
14:00:08,896 ERROR [stderr] (default task-1)     at br.com.fundaplub.model.service.AuthUserServiceLocal$2118543206$Proxy$_$$_Weld$EnterpriseProxy$.delete(Unknown Source)
14:00:08,896 ERROR [stderr] (default task-1)     at br.com.fundaplub.web.controller.user.UserController.delete(UserController.java:108)
14:00:08,896 ERROR [stderr] (default task-1)     at br.com.fundaplub.web.controller.user.UserController$Proxy$_$$_WeldClientProxy.delete(Unknown Source)
14:00:08,896 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:00:08,897 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
14:00:08,897 ERROR [stderr] (default task-1)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
14:00:08,897 ERROR [stderr] (default task-1)     at java.lang.reflect.Method.invoke(Unknown Source)
14:00:08,897 ERROR [stderr] (default task-1)     at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:38)
14:00:08,897 ERROR [stderr] (default task-1)     at net.vidageek.mirror.invoke.MethodHandlerByMethod.withArgs(MethodHandlerByMethod.java:54)
14:00:08,897 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.observer.ExecuteMethod.execute(ExecuteMethod.java:87)
14:00:08,897 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:00:08,898 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
14:00:08,898 ERROR [stderr] (default task-1)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
14:00:08,898 ERROR [stderr] (default task-1)     at java.lang.reflect.Method.invoke(Unknown Source)
14:00:08,898 ERROR [stderr] (default task-1)     at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93)
14:00:08,898 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:266)
14:00:08,898 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:253)
14:00:08,899 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:232)
14:00:08,899 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:169)
14:00:08,899 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:165)
14:00:08,899 ERROR [stderr] (default task-1)     at org.jboss.weld.event.TransactionalObserverNotifier.notifyObserver(TransactionalObserverNotifier.java:46)
14:00:08,899 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:119)
14:00:08,899 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:112)
14:00:08,900 ERROR [stderr] (default task-1)     at org.jboss.weld.event.EventImpl.fire(EventImpl.java:83)
14:00:08,900 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:78)
14:00:08,900 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:98)
14:00:08,900 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.interceptor.FlashInterceptor$Proxy$_$$_WeldClientProxy.intercept(Unknown Source)
14:00:08,900 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:58)
14:00:08,900 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:83)
14:00:08,901 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.interceptor.AspectStyleInterceptorHandler.execute(AspectStyleInterceptorHandler.java:90)
14:00:08,901 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:83)
14:00:08,901 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:75)
14:00:08,901 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor$Proxy$_$$_WeldClientProxy.intercept(Unknown Source)
14:00:08,901 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:58)
14:00:08,901 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:83)
14:00:08,901 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.core.DefaultInterceptorStack.start(DefaultInterceptorStack.java:93)
14:00:08,902 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.core.DefaultInterceptorStack$Proxy$_$$_WeldClientProxy.start(Unknown Source)
14:00:08,902 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.observer.RequestHandlerObserver.handle(RequestHandlerObserver.java:86)
14:00:08,902 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:00:08,902 ERROR [stderr] (default task-1)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
14:00:08,902 ERROR [stderr] (default task-1)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
14:00:08,902 ERROR [stderr] (default task-1)     at java.lang.reflect.Method.invoke(Unknown Source)
14:00:08,903 ERROR [stderr] (default task-1)     at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93)
14:00:08,903 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:266)
14:00:08,903 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:253)
14:00:08,903 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:232)
14:00:08,903 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:169)
14:00:08,903 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:165)
14:00:08,904 ERROR [stderr] (default task-1)     at org.jboss.weld.event.TransactionalObserverNotifier.notifyObserver(TransactionalObserverNotifier.java:46)
14:00:08,904 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:119)
14:00:08,904 ERROR [stderr] (default task-1)     at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:112)
14:00:08,904 ERROR [stderr] (default task-1)     at org.jboss.weld.event.EventImpl.fire(EventImpl.java:83)
14:00:08,904 ERROR [stderr] (default task-1)     at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:116)
14:00:08,904 ERROR [stderr] (default task-1)     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:56)
14:00:08,905 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
14:00:08,905 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
14:00:08,905 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
14:00:08,905 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
14:00:08,905 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
14:00:08,905 ERROR [stderr] (default task-1)     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
14:00:08,906 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
14:00:08,906 ERROR [stderr] (default task-1)     at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52)
14:00:08,906 ERROR [stderr] (default task-1)     at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)
14:00:08,906 ERROR [stderr] (default task-1)     at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
14:00:08,907 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
14:00:08,907 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)
14:00:08,907 ERROR [stderr] (default task-1)     at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
14:00:08,907 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
14:00:08,908 ERROR [stderr] (default task-1)     at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
14:00:08,908 ERROR [stderr] (default task-1)     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
14:00:08,908 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
14:00:08,908 ERROR [stderr] (default task-1)     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
14:00:08,908 ERROR [stderr] (default task-1)     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
14:00:08,908 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
14:00:08,909 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
14:00:08,909 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
14:00:08,909 ERROR [stderr] (default task-1)     at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
14:00:08,909 ERROR [stderr] (default task-1)     at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168)
14:00:08,909 ERROR [stderr] (default task-1)     at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687)
14:00:08,909 ERROR [stderr] (default task-1)     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
14:00:08,910 ERROR [stderr] (default task-1)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
14:00:08,910 ERROR [stderr] (default task-1)     at java.lang.Thread.run(Unknown Source)

É possível obter esse código ( ORA-02292) através do vraptor/jpa/java/wildfly ?

Abraço.

1
  • 1
    Seu problema na verdade está no modo de excluir que você está fazendo errado, por isso que você tem a mensagem: java.lang.IllegalArgumentException: Removing a detached instance br.com.fundaplub.model.entity.AuthUser#62 Não adianta pegar o código oracle, seu erro é de JPA. antes de excluir você precisa buscar a entity no banco de dados.
    – uaiHebert
    Commented 19/05/2014 às 21:24

2 Respostas 2

5

Felipe, esse erro está relacionado ao JPA, mais precisamente ao contexto de persistência. Você está removendo uma entidade usando o EntityManager, porém sua entidade ainda não está no contexto de persistência. Para resolver o problema você deve usar:

@Repository
public class AuthUserRepository {
    public void delete(AuthUser authUser) { //detached user
        AuthUser found = em.find(AuthUser.class, authUser.getId());
        //found agora está em seu contexto de persistencia
        if(found != null){
           em.remove(found);
           em.flush();
        }
        else{
            //nao existe
        }
    }
}

Note que que o .getId() é o attributo annotado com @Id. Aconselho fazer de seu AuthUserRepository um EJB para que se possa usar as facilidades do CMT. Caso esteja realmente ultilizando do BMT, é só injetar:

 @Resource
  UserTransaction utx;
  public void delete(AuthUser authUser) {
     utx.begin();
     AuthUser a = em.find(...);
     em.delete(a);
     utx.commit();
  }

Caso, não seja exatamente essa a resposta que você procura é só retornar. Links úteis: Container managed transaction

Bean Managed transaction

3
  • Olá Josué, muito obrigado pela sua resposta, porém o meu objetivo é capturar/obter o código do erro gerado pelo Oracle, pois no meu banco possui diversos erros e/ou mensagens customizadas ;) . E estou usando o Wildfly para controlar minha transação, mas irei dar uma olhada nos seu links. Muito obrigado maninho. Commented 21/05/2014 às 12:00
  • @FelipePassos, você deve ser capaz de capturar esses erros através do próprio SQLException, nunca usei com mensagens customizadas, só um palpite.
    – Josh
    Commented 21/05/2014 às 19:38
  • Realmente este era o erro :P A mesnagem do Oracle não vem no Exception porque havia este erro do JPA, logo o comando nem chegava no banco ;). Commented 28/05/2014 às 15:12
3

Eu tenho um projeto no github que talvez ajude no que você precisa. Ele foi desenvolvido para esses tipos de problemas.

Funciona assim: ele pega a constraint na mensagem de erro e busca na base de dados pela mensagem referente a ela.

Interface de auxílio:

package br.com.handlingjpa;

/**
 * Interface usada para identificar qual é a classe de entidade que
 * representa a tabela de mensagens
 * 
 * @author Thiago Santos <[email protected]>
 * 
 */
public interface IMessage {

    /**
     * Obt&eacute; o nome da constraint encontrada
     * 
     * @return A constraint encontrada
     */
    String getConstraint();

    /**
     * Defini qual foi a constraint encontrada na exce&ccedil;&atilde;
     * 
     * @param constraint
     *            O nome da constraint
     */
    void setConstraint(String constraint);

    /**
     * Obt&eacute; a mensagem referente a contraint
     * 
     * @return A mensagem
     */
    String getMessage();

    /**
     * Determina qual &eacute; a mensagem referente a constraint
     * 
     * @param message
     *            A mensagem
     */
    void setMessage(String message);

    /**
     * Obt&eacute; a express&atilde;o regular que determina como encontrar uma
     * constraint
     * 
     * @return A express&atilde;o regular
     */
    String getRegex(); 

}

Classe que faz o trabalho:

/*
 * Copyright (c) 2014. All rights reserved. 
 */
package br.com.handlingjpa;

import java.sql.SQLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 * <p>
 * A classe <code>HandlingDBException</code> &eacute; utilizada para tratar
 * erros gerado pela base de dados. A mesma busca na exce&ccedil;&atilde;o a
 * resposta dada pela base de dados do ocorrido) por um identificador do erro.
 * Ao encontrar-lo, a classe realiza uma consulta em busca da mensagem
 * correspondente.
 * </p>
 * 
 * @author Thiago Santos <[email protected]>
 * 
 */
public class HandlingDBException {

    /**
     * A classe de entidade que faz refer&ecirc;ncia a tabela de mensagens
     */
    private IMessage entityClass;
    /**
     * O nome da <code>NamedQuery</code> usada para consulta
     */
    private String namedQuery;
    /**
     * O nome do par&acirc;metro na <code>NamedQuery</code> usado como filtro
     */
    private String paramName;

    /**
     * Cria um HandlingDBException e determina quem &eacute; a classe de
     * entidades, o nome da NamedQuery e o identificador do par&acirc;metro na
     * NamedQuery
     * 
     * @param entityClass
     *            A <b>inst&acirc;ncia</b> da classe de entidade. Ex:
     *            <code>new Entidade()</code>
     * @param namedQuery
     *            O nome da NamedQuery de consulta
     * @param paramName
     *            O identificador do par&acirc;metro na NamedQuery
     */
    public HandlingDBException(IMessage entityClass, String namedQuery,
            String paramName) {
        this.entityClass = entityClass;
        this.namedQuery = namedQuery;
        this.paramName = paramName;
    }

    /**
     * Busca uma mensagem com base em um erro enviado pela base de dados. Caso
     * encontre, ser&aacute; adicionado a entidade a constraint encontrada e a
     * mensagem correspondente a ela. Caso contr&aacute;rio, ser&aacute;
     * retornado a entidade do jeito que foi passada no construtor
     * 
     * @param exception
     *            Um Throwable com a exce&ccedil;&atilde;o
     * @param connection
     *            A conex&atilde;o que diz onde executar a consulta
     * @return Retorna a pr&oacute;pria entidade passada no construtor
     */
    public IMessage getMessageFromDatabase(Throwable exception,
            EntityManager connection) {
        // Busca por uma SQLException ou ate que seja null
        while (exception != null && !(exception instanceof SQLException)) {
            exception = exception.getCause();
        }
        // Verifica se e uma SQLException
        if (exception instanceof SQLException) {
            SQLException ex = (SQLException) exception;
            // Monta a regex de constraint
            Pattern pattern = Pattern.compile(entityClass.getRegex());
            // Procura a ocorrencia na mensagem de erro
            Matcher matcher = pattern.matcher(ex.getMessage());
            // Verifica se achou alguma constraint
            if (matcher.find()) {
                // Obtem a constraint no meio da mensagem
                String constraint = ex.getMessage().substring(matcher.start(),
                        matcher.end());
                entityClass.setConstraint(constraint);
                // Busca a mensagem na base de dados
                Query query = connection.createNamedQuery(namedQuery);
                query.setParameter(paramName, constraint);
                String message = (String) query.getSingleResult();
                entityClass.setMessage(message);
            }
        }
        return entityClass;
    }
}

A descrição detalhada do projeto: Tratamento de exceção de base de dados com JPA

1
  • 1
    Tranquilo, @TiagoSilva, vou jogar os fontes na resposta!
    – Ascension
    Commented 4/07/2014 às 2:29

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .