• 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

Accessing local EJBs (JNDI problem)

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

I am practicing EJBs on jBoss 4.0.4 GA. I have one local SFSB which I can't access with the JNDI name I set in the jBoss.xml deployment descriptor ("shoppingCart/home") as the server gives it a random JNDI name on every deployment (e.g. "local/ShoppingCartSFSB@544217" the part after "@" keeps on changing).

Everytime I access the bean I am getting (as expected in such a situation):>
javax.naming.NameNotFoundException: ShoppingCartSFSB not bound

Necessary fragments of my apps deployment descriptors are given.
---------------------------------------------------------------------------
ejb-jar.xml contains:>
....
<session>
<ejb-name>ShoppingCartSFSB</ejb-name>
<local-home>project.ejb.ShoppingCartLocalHome</local-home>
<local>project.ejb.ShoppingCartLocal</local>
<ejb-class>project.ejb.ShoppingCartEJB</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
....
---------------------------------------------------------------------------
jboss.xml contains:>
....
<session>
<ejb-name>ShoppingCartSFSB</ejb-name>
<jndi-name>shoppingCart/home</jndi-name>
</session>
....
---------------------------------------------------------------------------

I am using following statement to access this EJB :>
---------------------------------------------------------------------------
ShoppingCartLocalHome sch=(ShoppingCartLocalHome)PortableRemoteObject.narrow (init.lookup("shoppingCart/home"), ShoppingCartLocalHome.class);
---------------------------------------------------------------------------

Though I stated "shoppingCart/home"as the jndi name to use in the jboss.xml the server shows while deploying that the ShoppingCartSFSB is bound to "local/ShoppingCartSFSB@***" where *** is a number displayed different every time the app is deployed (e.g "local/ShoppingCartSFSB@544217"). i.e. the JNDI name is different on every deployment.

I also tried using following statement but it failed too :>
---------------------------------------------------------------------------
ShoppingCartLocalHome sch=(ShoppingCartLocalHome)PortableRemoteObject.narrow (init.lookup("local/ShoppingCartSFSB"), ShoppingCartLocalHome.class);
---------------------------------------------------------------------------

How can set a particular JNDI name that will remain unchanged on every deployment.

Thank you.
 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lalit,

How do you set the InitialContext? You must set the InitialContext before you can do any JNDI stuff.

Regards,
Darya
 
Lalit Nagalkar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Darya;

I used
------------------------------------------
InitialContext init=new InitialContext();
-----------------------------------------
as you can see the init variable in the statements I posted.

Pleazzz help someone
Lalit
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the server shows while deploying that the ShoppingCartSFSB is bound to "local/ShoppingCartSFSB@***" where *** is a number displayed different every time the app is deployed (e.g "local/ShoppingCartSFSB@544217"). i.e. the JNDI name is different on every deployment.


Does this help:
WhyDoesTheLocalNameContainARandomNumber
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lalit Nagalkar:
hi Darya;

I used
------------------------------------------
InitialContext init=new InitialContext();
-----------------------------------------
as you can see the init variable in the statements I posted.

Pleazzz help someone
Lalit



Hi Lalit,

you can not just call InitialContext(). You first have to create your JBoss context.

Use the following lines before you call new InitialContext():



Regards,
Darya
 
Every snowflake is perfect and unique. And every snowflake contains a very 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