ejb@glassfish.java.net

Re: EJB3.0 Local Interface Question

From: Kenneth Saks <Kenneth.Saks_at_Sun.COM>
Date: Thu, 14 Jan 2010 14:08:24 -0500

On Jan 14, 2010, at 1:18 PM, Mrutyunjay wrote:

>
> Hi
>
> To the question in glassfish:EJB FAQ,
> I have an EJB component with a Local interface. Can I access it from a web component in a different application?
>
> No. The EJB specification only requires access to an EJB component's local EJB interface from within the same application in the same JVM.
>
>
> Why is this so? In practical, we can have different EJB JARS and WARS with local EJB interfaces dwployed in the same application server.

Hi Mrutyunjay,

The main reason has to do with the expectation of classloading isolation between applications. Invocations through the Local EJB view have pass-by-reference semantics, which not only require that the callee and caller be in the same JVM, but also require that both have the same classloader for the Local interface itself. Some vendors support such a configuration but relying on that behavior isn't portable. This restriction should be less of an issue in EJB 3.1 since it's now possible to directly package an EJB component in a .war file. Previously, web->local EJB access meant having an .ear containing both a.war and ejb-jar.

> Even though the EJB and Servlet run in the same JVM of the application server, why is there no JNDI binding for local interfaces in EJB3.0?

This is somewhat related to the intra-application requirement. The original impetus for global EJB JNDI names was to provide code running in a *different* application (or JVM) to access a Remote EJB component. Since Local EJB components didn't support cross-application use, there was no need to provide a global EJB JNDI name.

In practice, it has turned out that easy global JNDI name lookups can be beneficial even for code running in the same application. They allow for a more dynamic lookup than is possible with the more statically defined @EJB/<ejb-local-ref> dependencies. That's why EJB 3.1 does define portable global JNDI names for the Local session bean client view. (https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#Are_Global_JNDI_names_portable_How_do) However, in GlassFish, such a lookup is only guaranteed to work from code running in the same application as the target Local EJB component.

 --ken

> As such why can't we do a DI for the local EJB even though they are in the same JVM. Using Remote EJB in this case maynot be good as there is some performance penalty for doing the marshalling and unmarshalling in case of Remote EJB's
>
> --
> Regards,
> Mrutyunjay
>
>
>
> --
> Regards,
> Mrutyunjay