This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Glassfish and the fly likes JNDI connection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Glassfish
Bookmark "JNDI connection problem" Watch "JNDI connection problem" New topic
Author

JNDI connection problem

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Hi all,

I have an ear in which there is a war and an ejb jar. In my ejb jar under META-INF there is glassfish-resources.xml. I created a jdbc-connection-pool whose name is java:app/mydb_pool. Then I created a resource which refers to this pool whose jndi name is "java:app/mydb".

In my ejb I created an InitialContext which lookups the jndi. I am getting error. Can anyone please explain me what is wrong. Here is the code and configuration.


Thank you all in advance.


Love all, trust a few, do wrong to none.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2564
    
    9

The IntialContext lookup the JNDI name not the pool name. You probably typed wrong in the XML.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Oops!! My bad, corrected it. Its just a typing mistake. But my code is right. I get the error
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Previously I was using glassfish 3.0, then I tried to deploy it on 3.1.2. Then I got this error while deployingThen I changed the scope to java:module. Even then I am not able to lookup the jndi name from my EJB.

Any ideas?
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

I tried checking whether the resources are being created are not. So I removed the lookup code from my EJB's constructor and then redeployed the application and listsed the resources using

asadmin --host localhost --user admin --port 20048 list-applications --subcomponents --resources

I was able to see the resources. Somehow the jndi lookup is not working.

Can anyone please tell me what am I missing.

Thank you all in advance.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Holy shit!! Its working if I use @Resources annotation. But with InitialContext its not working.

Any ideas?
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Sorry!! I just came to know that only in post construct I can do that. The issue is resolved now
 
 
subject: JNDI connection problem