wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes EJBContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "EJBContext" Watch "EJBContext" New topic
Author

EJBContext

rutuparna lastname
Greenhorn

Joined: Aug 01, 2009
Posts: 4
What is the diffrence between java:comp/ and java:comp/env/

ref:--http://javahowto.blogspot.in/2006/06/4-ways-to-get-ejbcontext-in-ejb-3.html

may I know the diffrence between
1>java:comp/EJBContext
2>java:comp/env/com.foo.ejb.HelloBean/sctx
3>java:comp/env/sessionContext


Christian Ludt
Greenhorn

Joined: Apr 07, 2009
Posts: 11
What is the diffrence between java:comp/ and java:comp/env/


Imagine both as directories on your file system. You might have files (environment entries) in both directories (contexts).

The java:comp namespace exists per component (like the "My Documents" folder exists for each user on Microsoft Windows). By default, environment entries declared by the components are created in java:comp/env. The Java EE 6 specification recommends (but not requires) that environment entries be created in the env subcontext to avoid potential conflicts with current or future versions of the specification. I.e. the future versions of the spec may require that certain entries be created in the java:comp context - as EJBContext already is.

ref:--http://javahowto.blogspot.in/2006/06/4-ways-to-get-ejbcontext-in-ejb-3.html

may I know the diffrence between
1>java:comp/EJBContext
2>java:comp/env/com.foo.ejb.HelloBean/sctx
3>java:comp/env/sessionContext


In this case, if you imagine the contexts again as directories on your file system, you can imagine the entries 2 and 3 as symbolic links to java:comp/EJBContext.

Symbolic link 2 java:comp/env/com.foo.ejb.HelloBean/sctx is created because that is the default: full qualified class name (com.foo.ejb.HelloBean) + "/" + name of member variable (sctx):



Symbolic link 3 java:comp/env/sessionContext is created because the code explicitly says so in the name attribute of the Resource annotation:



Sidenote:
Even though the 4 ways to get the EJBContext in EJB 3.1 are correct, I do not see why I should use JNDI lookup if I already have access via the member variable. Nevertheless, it demonstrates nicely under which entry an object is made available.

Christian Ludt
Greenhorn

Joined: Apr 07, 2009
Posts: 11
BTW: casting the EJBContext to a SessionContext only works because the EJBContext is accessed in an EJB session bean. If you accessed the EJBContext in a MessageDrivenBean, it would be a MessageDrivenContext; in an Entity bean it would be an EntityContext.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJBContext