• 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

JNDI names for EJBs

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'm absolutely new to ejb, so this is a silly question. I can access the EJBs from web container using @EJB annotation. But, when i try to use JNDI, the server log shows that the JNDI name does not exist. I'm using glassfish. Can somebody tell me how the default jndi names are used in glassfish, and how i can modify and assign custom jndi names?
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ray!
The JNDI configuration for glassfish server is contained in the library - appserv-rt.jar. So when you annotate the bean with @Stateless or @Stateful give the mapped name for the bean.
For e.g

then when you look up for the bean in the client provide the code as follows.

For e.g


where RemovableRemote is the Remote Interface,
Removable is the mapped name.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glassfish's "Using the Java Naming and Directory Interface" ( https://glassfish.dev.java.net/javaee5/docs/DG/beanr.html ) could be great help and don't forget to have a look at section "Accessing EJB Components Using the CosNaming Naming Context" ( https://glassfish.dev.java.net/javaee5/docs/DG/beanr.html#beanu )
 
Debasish Ray Chawdhuri
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! but it still does not work

Here is the EJB



Here is the Local interface



And here is the servlet



now i have used the following request parameters.. but none of them works

java:comp/env/TestSession

TestSession

i am not having any ejb-jar.xml
[ February 27, 2008: Message edited by: Debasish Ray Chawdhuri ]
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your servlet part of the same application as the EJB? If not, then it won't work because the EJB only exposes a local interface rather than a remote interface.
 
Debasish Ray Chawdhuri
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, its part of the same application.. that is the ejb and the web application are in the same ear file
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not narrow the object returned from the JNDI lookup unless you have a remote interface.

More seriously, you must have the ejb-jar.xml file in your EAR. It is mandatory to have this deployment descriptor for the EJB.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by palla sridhar:


then when you look up for the bean in the client provide the code as follows.

For e.g


where RemovableRemote is the Remote Interface,
Removable is the mapped name.



I know this may be laughable but I'm also very new at this. Do I need to import the EJB application in the client application i.e have the .ear? If not, how is class "RemovableRemote" visible to the client at compile time? I understand how it works for local client since they'll be sharing the same JVM, but for remote I'm really confused.
 
palla sridhar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vusa!
Please check this link. http://www.netbeans.org/kb/60/javaee/ejb-glassfish-maven.html

In that tutorial, the following is quoted.

Using the @Stateless annotation mappedName attribute allows you to assign names which you can use to search the EJB bean through the remote client



So you can use the EJB from even the remote client, but you need to import the package name the EJB is in the .ear.!!
 
Debasish Ray Chawdhuri
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You should not narrow the object returned from the JNDI lookup unless you have a remote interface.

More seriously, you must have the ejb-jar.xml file in your EAR. It is mandatory to have this deployment descriptor for the EJB.



I thought ejb-jar.xml is optional in EJB3.0 spec. However even using an ejb-jar.xml did not work.

what exactly do i write in my ejb-jar.xml when i already have all the information in annotations
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic