Weblogic escondendo exceção do Hibernate

22 01 2015

Problema

Ao testar o mapeando de novas entidades no Weblogic 10.3 com EJB 2.0, quando ocorria uma exceção, o Weblogic não informava a causa especifica do problema, ou seja, escondia a exceção que vinha do Hibernate.

O método de de save do EJB estava com a seguinte anotação:

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

 javax.ejb.TransactionRolledbackLocalException: Error committing transaction:; nested exception is: weblogic.transaction.internal.AppSetRollbackOnlyException: setRollbackOnly called on transaction
 at weblogic.ejb.container.internal.EJBRuntimeUtils.throwTransactionRolledbackLocal(EJBRuntimeUtils.java:232) ~[weblogic.jar:10.3.3.0]
 at weblogic.ejb.container.internal.EJBRuntimeUtils.throwEJBException(EJBRuntimeUtils.java:130) ~[weblogic.jar:10.3.3.0]
 at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:626) ~[weblogic.jar:10.3.3.0]
 at weblogic.ejb.container.internal.BaseLocalObject.__WL_postInvokeTxRetry(BaseLocalObject.java:427) ~[weblogic.jar:10.3.3.0]
 at com.empresa.ngpc.session.consumerin.ProcessDocumentInBean_5943ts_ProcessDocumentInImpl.processDocument(ProcessDocumentInBean_5943ts_ProcessDocumentInImpl.java:65) ~[ProcessDocumentInBean_5943ts_ProcessDocumentInImpl.class:na]
 at com.empresa.ngpc.session.consumerin.ConsumerInBean.consumeQueue(ConsumerInBean.java:170) ~[ngproxy-connector-2.8.0.jar:na]
 at sun.reflect.GeneratedMethodAccessor526.invoke(Unknown Source) ~[na:na]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_22]
 at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_22]
 at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.jee.intercept.MethodInvocationInvocationContext.proceed(MethodInvocationInvocationContext.java:104) [com.bea.core.repackaged.springframework.pitchfork_1.3.0.0_1-0.jar:1.0]
 at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44) [jboss-seam-wls-2.2.2.Final.jar:2.2.2.Final]
 at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:101) [jboss-seam-wls-2.2.2.Final.jar:2.2.2.Final]
 at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50) [jboss-seam-wls-2.2.2.Final.jar:2.2.2.Final]
 at sun.reflect.GeneratedMethodAccessor527.invoke(Unknown Source) ~[na:na]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_22]
 at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_22]
 at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.jee.intercept.JeeInterceptorInterceptor.invoke(JeeInterceptorInterceptor.java:69) [com.bea.core.repackaged.springframework.pitchfork_1.3.0.0_1-0.jar:1.0]
 at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37) [com.bea.core.repackaged.springframework.pitchfork_1.3.0.0_1-0.jar:1.0]
 at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54) [weblogic.jar:10.3.3.0]
 at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50) [com.bea.core.repackaged.springframework.pitchfork_1.3.0.0_1-0.jar:1.0]
 at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) [com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar:2.5.3]
 at $Proxy328.consumeQueue(Unknown Source) [na:na]
 at com.empresa.ngpc.session.consumerin.ConsumerInBean_450m52_ConsumerInImpl.consumeQueue(ConsumerInBean_450m52_ConsumerInImpl.java:53) [ConsumerInBean_450m52_ConsumerInImpl.class:na]
 at com.empresa.ngpc.controller.ConsumerTask.executeNow(ConsumerTask.java:119) [ngproxy-connector-2.8.0.jar:na]
 at com.empresa.ngpc.controller.ConsumerTask.run(ConsumerTask.java:94) [ngproxy-connector-2.8.0.jar:na]
 at java.util.TimerThread.mainLoop(Timer.java:512) [na:1.6.0_22]
 at java.util.TimerThread.run(Timer.java:462) [na:1.6.0_22]
 Caused by: weblogic.transaction.internal.AppSetRollbackOnlyException: setRollbackOnly called on transaction
 at weblogic.transaction.internal.TransactionImpl.setRollbackOnly(TransactionImpl.java:544) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at weblogic.transaction.internal.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:325) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at weblogic.transaction.internal.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:318) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:421) ~[hibernate-entitymanager-3.4.0.GA.jar:3.4.0.GA]
 at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:605) ~[hibernate-entitymanager-3.4.0.GA.jar:3.4.0.GA]
 at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:513) ~[hibernate-entitymanager-3.4.0.GA.jar:3.4.0.GA]
 at weblogic.transaction.internal.ServerSCInfo.doBeforeCompletion(ServerSCInfo.java:1214) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:1189) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:109) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1301) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:2117) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:257) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:224) ~[com.bea.core.transaction_2.6.1.0.jar:2.6.1.0]
 at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:594) ~[weblogic.jar:10.3.3.0]
 ... 38 common frames omitted

 

Solução

Como o Weblogic escondia a exceção causa raiz ao finalizar a transação gerenciada por ele, foi necessário executar um flush “manual” em um try/catch, e assim foi possível capturar a exceção do Hibernate e corrigir o mapeamento.

Abaixo segue o código que utilizei para executar o flush manual:

    @In
    private EntityManager entityManager;
	
    @Override
    public void flush() {
        entityManager.flush();
    }

FONTE

Anúncios

Ações

Information

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s




%d blogueiros gostam disto: