Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI connection problem

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The IntialContext lookup the JNDI name not the pool name. You probably typed wrong in the XML.

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops!! My bad, corrected it. Its just a typing mistake. But my code is right. I get the error
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Holy shit!! Its working if I use @Resources annotation. But with InitialContext its not working.

Any ideas?
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry!! I just came to know that only in post construct I can do that. The issue is resolved now
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic