tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From is_maximum <>
Subject Re: suggestion for defining local ref name for session beans
Date Sun, 13 Sep 2009 19:25:14 GMT

Quintin Beukes-2 wrote:
> Yes, you can create a mapped name when defining each EJB (part of the
> @Stateless annotation), and then inside the facade session bean you
> can lookup the others doing something like this:
> InitialContext ctx = new InitialContext();
> Object lookedUpEJB = ctx.lookup(otherEjbsMappedName);
> Then lookedUpEJB will contain a reference to the EJB. you can wrap
> this in a static method of either the facade bean or some other class.
> When initializing an InitialContext without constructor arguments, it
> is for the local server by default, and therefore you can lookup any
> EJBs in the server.
> Also, if you don't explicitly define a mapped name for the EJB, it
> will default to ${beanImplementationClass}Local. So if you have the
> following:
> @Stateless
> public class MyBean implements MyLocal {}
> @Local
> public class MyLocal {}
> Then you can do the following to get a reference:
> private Object lookup(String name) throws NamingException {
>   return new InitialContext().lookup(name);
> }
> MyLocal bean = lookup("MyBeanLocal");
> Hope this helps,

Well thanks, But as far as I can remember, in EJB spec it is said not to use
"mappedName" because still it depends on the provider (or maybe container)
that how to retrieve that name and in some container it might be ignored!!
but using the @EJBs it is ensured that you still can lookup your local

And the naming style you stated "MyLocalBeanLocal" is defined for OpenEJB.
We are using OpenEJB in running our test cases but in application server it
is not the case. 

The purpose of this post is that I hope the EJB 3.1 get improved through
David. I know if this is the correct he will try to add such feature.

Thank you all guys


Mohammad Norouzi

Help each other to reach the future faster Pixelshot Photoblog Brainable Blog 

View this message in context:
Sent from the OpenEJB User mailing list archive at

View raw message