远程EJB调用的事务

时间:2012-12-24 10:56:51

标签: java-ee glassfish glassfish-3 ejb-3.1 corba

我有一个关于玻璃鱼交易和CORBA的奇怪问题。我可以解决问题,但我仍然不知道为什么会发生这种错误:

我有两个课程,我们称之为客户端 RemoteImpl 客户端位于一台服务器上,远程位于另一台服务器上。

客户端看起来像这样(更简单的例子,而不是真正的代码):

@Stateless
public class Client {

    @EJB(name = "TheRemoteEJB")
    protected Remote remoteEJB;

    @Schedule(hour = "*", minute = "*/5", persistent = false)
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public void doSomeStuff() {
      for(int i=0;i<300000;i++){
        remoteEJB.theMethodToCall(i);
        ... other code that may take a bit longer...
      }
    }
}

RemoteImpl 如下所示:

@Stateless
@Remote(RemoteInterface.class)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class RemoteImpl {

  @EJB
  private SomeJPAFacade facade;

  @Override
  public int theMethodToCall(int param) throws SomeException {
    Bean products = facade.findBySomeSelect(param);
    return bean.getAValue();
  }
}

其他使用的类是:

SomeException

public class SomeException extends Exception {
 public SomeException() {
   super();
 }
 public SomeException(String message) {
   super(message);
 }
}

RemoteInterface

public interface RemoteInterface {
  public int theMethodToCall() throws SomeException
}

问题是,当 doSomeStuff 花费太长时间时,会引发CORBA异常:

[#|2012-12-22T03:10:03.327+0100|INFO|glassfish3.1.2|com.foo.bar.Client|_ThreadID=47;_ThreadName=Thread-2;|javax.ejb.EJBException: javax.transaction.InvalidTransactionException: CORBA INVALID_TRANSACTION 0 No
; nested exception is:
    org.omg.CORBA.INVALID_TRANSACTION:   vmcid: 0x0  minor code: 0  completed: No
    at com.foo.bar.Client._Remote_Wrapper.theMethodToCall(com/foo/bar/_RemoteInterface_Wrapper.java)
    at com.foo.bar.Client.doSomeStuff(Client.java:73)
    at sun.reflect.GeneratedMethodAccessor3162.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:49)
    at sun.reflect.GeneratedMethodAccessor80.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundTimeout(SystemInterceptorProxy.java:149)
    at sun.reflect.GeneratedMethodAccessor371.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
    at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:4058)
    at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1832)
    at com.sun.ejb.containers.EJBTimerService.access$100(EJBTimerService.java:108)
    at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:2646)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.transaction.InvalidTransactionException: CORBA INVALID_TRANSACTION 0 No; nested exception is:
    org.omg.CORBA.INVALID_TRANSACTION:   vmcid: 0x0  minor code: 0  completed: No
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:281)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:213)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
    at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:227)
    at com.foo.bar.__RemoteInterface_Remote_DynamicStub.matchByParityId(com/foo/bar/__RemoteInterface_Remote_DynamicStub.java)
    ... 39 more
Caused by: org.omg.CORBA.INVALID_TRANSACTION:   vmcid: 0x0  minor code: 0  completed: No
    at com.sun.jts.CosTransactions.CurrentTransaction.sendingRequest(CurrentTransaction.java:812)
    at com.sun.jts.CosTransactions.SenderReceiver.sending_request(SenderReceiver.java:138)
    at com.sun.jts.pi.InterceptorImpl.send_request(InterceptorImpl.java:338)
    at com.sun.corba.ee.impl.interceptors.InterceptorInvoker.invokeClientInterceptorStartingPoint(InterceptorInvoker.java:290)
    at com.sun.corba.ee.impl.interceptors.PIHandlerImpl.invokeClientPIStartingPoint(PIHandlerImpl.java:376)
    at com.sun.corba.ee.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:304)
    at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:228)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:194)
    ... 42 more
Caused by: org.omg.CosTransactions.Unavailable: IDL:omg.org/CosTransactions/Unavailable:1.0
    at com.sun.jts.CosTransactions.TopCoordinator.get_txcontext(TopCoordinator.java:2787)
    at com.sun.jts.CosTransactions.ControlImpl.getTXContext(ControlImpl.java:824)
    at com.sun.jts.CosTransactions.CurrentTransaction.sendingRequest(CurrentTransaction.java:804)
    ... 49 more
|#]

我明确告诉ApllicationServer @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED),因为我不想跨越事务。但是这个例外似乎有一个交易。我一直以为交易不能跨越对另一个glassfish实例的远程调用?

我可以通过删除@TransactionAttribute并在客户端 - 类中添加@TransactionManagement(TransactionManagementType.BEAN)来解决问题。

但我仍然想知道为什么会发生这种错误。

感谢您的回复。

更新 Bugreport已在https://java.net/jira/browse/GLASSFISH-17535

下提交

1 个答案:

答案 0 :(得分:1)

NOT_SUPPORTED表示The container invokes an enterprise bean method whose transaction attribute NOT_SUPPORTED with an unspecified transaction context.

似乎未指定的上下文导致无效的事务异常。

通过使用bean托管事务,您告诉容器不要提供任何事务上下文,因此它可以防止该异常。

这对我来说感觉就像一个小虫子,我不太熟悉玻璃鱼,我的直觉告诉我这应该有效。