File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Few EJB questions [newbie] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Few EJB questions [newbie]" Watch "Few EJB questions [newbie]" New topic
Author

Few EJB questions [newbie]

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Howdy Ranchers!

I've just started entering the EJB world and few questions raised in my head. Excuse me if these are obvious ones :-)

As I understand the ENC is a private scope for a concrete EJB.
So, can you say it's like the init-param's in the servlets world?

Can a EJB A access the EJB's B ENC?

What is the relation between the ENC and JNDI? Is ENC a JNDI, is it a part of the JNDI or are these two entities unrelated with each other?

If I would like to have a scope where one EJB could take something from the other EJB - what should I use? Directly bind some entity in the JNDI and pass the location to another EJB or something else? Should the new EJB Singleton be used for such all EJB's common-space?

As I understand, every part of the application server can access some entry in the JNDI, so it's somewhat similar to the context-param (in contrast to the similarity of EJB's ENC <-> servlet's init-param)? By the way: is there a way to 'restrict' access to some resource in the JNDI? For example: EJB A and EJB B can access a resource in this JNDI location, but EJB C cannot access it.

Are the ENC parameters read only during deployment and CAN'T be changed at all after the deploy? I just was wandering that if it WOULD be possible to change the ENC value, you might end in an inconsistent EJB state.
I mean: I have a property marked with @Resource annotation which I inject with a value of "10". Container creates i.e. 5 instances of the EJB and put them in the pool. Then, somehow, I change the value of the ENC parameter to "20".
After this, container might decide to create few new EJB instances and add them to the pool. These new instances would have different property value injected ("20") and therefore I would end up with x instances with property value of "10" and y instances with property value of "20". As the container can choose which instance will be used to serve user's request, I would end in an inconsistent state of the EJB's.
Is this scenario even possible?

Thanks in advance for your time!

Cheers!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Logan Lee
Greenhorn

Joined: Oct 28, 2009
Posts: 18

Pedro Kowalski wrote:
What is the relation between the ENC and JNDI? Is ENC a JNDI, is it a part of the JNDI or are these two entities unrelated with each other?

The ENC is the component's individual space in the JNDI. It's just a name space in the JNDI.
The ENC is managed by the container.
You can access the resources defined in the ENC via JNDI lookup or via EJBContext methods.

Pedro Kowalski wrote:
Are the ENC parameters read only during deployment and CAN'T be changed at all after the deploy? I just was wandering that if it WOULD be possible to change the ENC value, you might end in an inconsistent EJB state.

EJB have read only access to the ENC/JNDI. You'll get a javax.naming.OperationNotSupported if you try to rebind variables. (this is on the exam)
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Thanks Logan!

Logan Lee wrote:EJB have read only access to the ENC/JNDI. You'll get a javax.naming.OperationNotSupported if you try to rebind variables. (this is on the exam)

Ok, this solves some problems but does it mean that the EJB cannot bind some object to the JNDI? Or maybe it just can't bind some object to the ENC?

Logan Lee
Greenhorn

Joined: Oct 28, 2009
Posts: 18

If you use @EJB or @resource in a ejb those resources are automaticallly made available in the ENC/jndi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Few EJB questions [newbie]