Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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: 800

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: 2242
    
    7

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
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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: 800

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: 800

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: 800

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: 800

Sorry!! I just came to know that only in post construct I can do that. The issue is resolved now
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JNDI connection problem
 
Similar Threads
Connecting jsp with derby
glassfish vs. Hibernate: JNDI configuration
Tutorial PostgreSQL 8.3 on Glassfish V2.1 for ConnectionPool in Netbeans 6.5.1, WindowsXP (Post 3)
MDB deployed in WebLogic and Queues in IBM MQ
ClassCastException when casting to home interface