• 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

EJB environment question.

 
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 all,
I have an ejb-jar with several EJB ( Session, Entity BMP, etc ). I want to pass to all EJB inside this JAR a parameter as an String ( i.e , the data source�s JNDI name they must to connect to)
and i know that a must use the JNDI naming context java:comp/env to access enterprise bean's environment.
The questions are :
* When i lookup for "java:comp/env" what Java type will be returned ?
* How to get the environment entries ?
* Once on the EJB descriptor, the env-entry
is related to some EJB. But how can i define only one env-entry and it be acessed by all EJB�s on the application.
If anyone knows an document with this answers, please tell me where to find.
Any help will be apreciated.
Claudio Gualberto.
SCJP 1.4
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When i lookup for "java:comp/env" what Java type will be returned ?


javax.naming.Context

How to get the environment entries ?


Context envContext = <jndi lookup for java:comp/env>
String property = (String) envContext.lookup("MyEnvEntry");

Once on the EJB descriptor, the env-entry
is related to some EJB. But how can i define only one env-entry and it be acessed by all EJB�s on the application.


I am not aware of a way to do this (which by far doesn't mean that there wouldn't be a way)...
 
Claudio Gualberto
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help, the last question is really hard to find the answer.
Maybe there is another way to do what i want.
Let�s see :
I have some DataSources that maps the same data base schema, but to diferent data base instances.
I would like easily change the DataSource name by changing something on the deployment descriptor
or other place, thus my beans will get connections from several sources with no change on the code.
Do you have some idea ?
Claudio Gualberto.
SCJP 1.4
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have some DataSources that maps the same data base schema, but to diferent data base instances. I would like easily change the DataSource name by changing something on the deployment descriptor or other place, thus my beans will get connections from several sources with no change on the code.


The thing you need to change is the vendor-specific deployment descriptor. That's where you actually point the datasource into a database instance (and define usernames, passwords, etc). You need to consult your appserver's documentation on this one.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic