如果最后一个EJBBean方法抛出SystemException,EJB容器是否会删除调用层次结构中的所有EJB对象?

时间:2014-05-19 13:31:40

标签: java ejb java-ee-6

以下是一些sudo代码:

//controller method
public String method1()
{
    EJBBean1 bean1;
    bean1.method1();
}

//EJBBean1 class
public void method1()
{
    EJBBean2 bean2;
    bean2.method2();
}

//EJBBean2 class
public void method2()
{
    EJBBean3 bean3;
    bean3.method3();
}

//EJBBean3 class
public void method3()
{
    throw NullPointerException();
}

EJB对象是通过依赖注入注入的。

如果EJBBean3的method3抛出SystemException,EJB容器是否会删除所有EJB对象(EJBBean1,2& 3)?

2 个答案:

答案 0 :(得分:1)

正常情况下

嵌套的StateFullEJB具有特殊行为,包含的EJB保存会话。

在你的情况下,当EjbBean1被破坏时,EjbBean1拥有新的专用EjbBean2,EjbBean2也会被破坏。同样的情况适用于EjbBean2 - EjbBean3。

因此EjbBean1负责在EjbBean1.remove方法(@Remove方法)中调用EjbBean2.remove中的remove。

Samples

对于例外情况......

    When ever a System Exception thrown by a bean method, EJB Container invalidates 
the EJB object and destroys the bean instance.The bean instance directly moved into
 DOES not exists state and any @PreDestroy methods are not invoked.

A System  exception is any unchecked Exception not annotated as an @Application Exception 

参考here

因此,EjbBean3将被Ejb容器自动销毁,异常传播到Parent方法EjbBean2和EJbBean1。因为没有bean捕获NullPointerException 这些实例将由容器自动删除。

NOte **,假设NullPointerException是一个系统异常(即没有注释/配置)

答案 1 :(得分:0)

只有它们不是@Singleton beans。