• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling EJB3.0 from another EJB3.0

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi all,
We all know that in EJB3.0 we can use @EJB annotaton to lookup the EJB either from Web Tier or application client or from another EJB also.all of these is working fine.

but EJB3.0 says that while calling EJB from another EJB it could also be done like following from one EJB3.0 :

@Resource private javax.ejb.SessionContext context;
public void myMethod() {
BankMgr bankMgr = (BankMgr)context.lookup(“ejb/BankMgr”);
}

Using SessionContext.
but when i try doing it i get an error saying NameNotFound for the 2nd EJB from 1st EJB??
no idea why???

apart from that how many names a EJB can have & if it has many then by what name should we look up??
for e.g
1)what is the name of EJB if we dnt give any name at all (nither JNDI nor mappedName)
2)what is mappedName (used with @Stateful & @Stateless)(after giving it can we lookup using old name)
3)what are implications of giving mappedName?
4)what is JNDI name for EJB?
5)how & where to give JNDI name to an EJB?(after giving it can we lookup using old name)
6)what is reference name for an EJB?(used in web tier in web.xml in <ejb-ref> element?
:roll: ops: :twisted:
Please help..............
I m using NetBeans6.5.10 & Glassfish V2

Thanks in advance.....................
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I will try to answer your questions the best as I can.

1. The default name of a session bean is the fully qualified class that it implements, i.e. SessionBean implements Foo.SomeRemoteInterface then that name attribute of SessionBean is bound to Foo.SomeRemoteInterface
2. mappedName bounds that session bean to a global variable in the RMI registry, but not all application server vendors are required to support this functionality
3. See #2 Assigning a mappedName may break portability across different application server vendors
4. See #1 - You can perform that following (assuming no ejb-jar.xml is used and default annotation values), then you can do the following



5. ejb-ref is that bound name for the session bean

For the purpose of SessionContext, you do not need to access this directly. If you really want to, the you can to modify the ejb-jar.xml to include the following information -



This deployment descriptor simply injects a session bean that implements the remote interface, bind to the the value of ejb-ref-name. Therefore, you can do the lookup on the SessionContext. I should note that the SessionContext is not aware of any global variables except for the ones declared in the ejb-jar.xml

I hope this information helps.


 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dhiren,

You may also declare a component dependency using @Resource on the class. Kindly check with a good EJB 3.0 resource for futher details. The GlassFish docs, for example, are pretty decent.

Best regards,
Reza
 
Dhiren Lodhia
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jerwin Louise Uy wrote:Hi,

I will try to answer your questions the best as I can.

1. The default name of a session bean is the fully qualified class that it implements, i.e. SessionBean implements Foo.SomeRemoteInterface then that name attribute of SessionBean is bound to Foo.SomeRemoteInterface
2. mappedName bounds that session bean to a global variable in the RMI registry, but not all application server vendors are required to support this functionality
3. See #2 Assigning a mappedName may break portability across different application server vendors
4. See #1 - You can perform that following (assuming no ejb-jar.xml is used and default annotation values), then you can do the following



5. ejb-ref is that bound name for the session bean

For the purpose of SessionContext, you do not need to access this directly. If you really want to, the you can to modify the ejb-jar.xml to include the following information -



This deployment descriptor simply injects a session bean that implements the remote interface, bind to the the value of ejb-ref-name. Therefore, you can do the lookup on the SessionContext. I should note that the SessionContext is not aware of any global variables except for the ones declared in the ejb-jar.xml

I hope this information helps.




Thanks alot Jerwin
i did get some of doubts cleared specially about mappedName,i had thought it will be good to for ejb to give mappedName and will make ejb universally accessible from any where,didn't know that it is not in J2EE SPEC .
but i had a reason to believe that let me tell you one scenario ,
one i was trying to look up an EJB from remote standalone java POJO client and i kept getting the error of name not found till i gave the EJB mappedName.then it worked fine.

btw regarding SessionContext look up of EJB from EJB ,
i know that we don't need to do that we have many other ways but till i need to do it because its mentioned in Sun's EJB course FJ310 and hence i m required to show it practically to students.
i did read your post carefully and tried all you said but still it didn't work
i m posting here the code of mini project that i have made
please have a look at the code and let me know if any mistake is there ..........

i have made this Enterprise Application in NetBeans 6.1 and Glassfish AS
code of calling Second EJB from First using SessionContext is as follows :


please let me know if any thing more can be done..........
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dhiren,

Yes. That will cause the error because the deployment descriptor is wrong.

Here is the modified ejb-jar.xml



Regards.
 
Dhiren Lodhia
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jerwin Louise Uy wrote:Hi Dhiren,

Yes. That will cause the error because the deployment descriptor is wrong.

Here is the modified ejb-jar.xml



Regards.



Thanks a ton Jerwin,
it finally worked for me.
have no words to thank you,
will keep in touch with you .......
Regards Dhiren

 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic