JPA, Oracle and Handling Exceptions

3

I'm using vraptor 4, JPA and Oracle.

But when an exception occurs during persistence, the error code that Oracle generates is not coming along with Exeption.

This is the Repository

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

And this is the service that calls the 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();
        }
    }
}

When the service is called to remove AuthUser and it has some relationship with other tables ORACLE generates the error:

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

This is 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)

Is it possible to get this code (ORA-02292) through vraptor / jpa / java / wildfly?

Hug.

    
asked by anonymous 19.05.2014 / 22:14

2 answers

5

Felipe, this error is related to JPA, more precisely to the context of persistence. You are removing an entity using EntityManager, but your entity is not yet in the context of persistence. To resolve the problem you should use:

@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 that the .getId () is the attribute annotated with @Id. I suggest making your AuthUserRepository an EJB so that you can use the CMT facilities. If you are really using the BMT, just inject:

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

If this is not exactly the answer you are looking for, just return. Useful links: Container managed transaction

Bean Managed transaction

    
20.05.2014 / 01:51
3

I have a project in github that might help with what you need. It was developed for these types of problems.

It works like this: it takes the constraint in the error message and searches the database for the message about it.

Help interface:

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(); 

}

Class that does the work:

/*
 * 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;
    }
}

Detailed description of the project: Database exception handling with JPA

    
04.07.2014 / 03:34