Page 1 of 1
About Question enthuware.oce-ejbd.v6.2.557 :
Posted: Tue Dec 10, 2013 3:43 pm
by zoot11
How can this be correct?
Code: Select all
(ManagerLocal)sessionContext.lookup("com.enthu.ejbplus.TellerBean/manager");
TellerBean does not implement an interface called ManagerLocal. Or what is going on?
Re: About Question enthuware.oce-ejbd.v6.2.557 :
Posted: Tue Dec 10, 2013 8:48 pm
by admin
It is not trying to cast TellerBean to ManagerLocal. It is using a bean bound to the name "com.enthu.ejbplus.TellerBean/manager" and that bean implements ManagerLocal. The code for that bean is not relevant and is not shown in this question.
HTH,
Paul.
Re: About Question enthuware.oce-ejbd.v6.2.557 :
Posted: Wed Dec 11, 2013 3:57 am
by zoot11
admin wrote:The code for that bean is not relevant and is not shown in this question.
But the code shows a bean named com.enthu.ejbplus.TellerBean!
Re: About Question enthuware.oce-ejbd.v6.2.557 :
Posted: Wed Dec 11, 2013 5:15 am
by admin
TellerBean's code is trying to use a bean that implements ManagerLocal. It does not say that TellerBean implements ManagerLocal. For the purpose of the question, TellerBean's code that does the lookup is the only code that is relevant and so that is what is shown.
Re: About Question enthuware.oce-ejbd.v6.2.557 :
Posted: Sat Feb 08, 2014 8:39 pm
by vinkjrwl
The lookup being done in ENC is relying on
manager variable defined in this class for
com.enthu.ejbplus.ManagerLocal and since @EJB annotation is already used here, the reference to ManagerLocal can always be found using "
manager" variable. What is confusing is , the use of "manager" variable in jndi lookup.
Code: Select all
ManagerLocal manager = (ManagerLocal) ctx.lookup("java:comp/env/com.enthu.ejbplus.TellerBean/manager")
Its like, until or unless you define a variable for ManagerLocal (in this case "manager" ), lookup cannot be done, but if I have already defined it and its already injected with @EJB, then whats the point of doing the lookup?
Can you please help?
Re: About Question enthuware.oce-ejbd.v6.2.557 :
Posted: Sat Feb 08, 2014 10:24 pm
by admin
There is no point in this case for doing the look up again. However, the question is just trying to cover the point that an injected variable can also be looked up from a namespace. It may be helpful for a helper class that does not have access to the instance variable.
Re: About Question enthuware.oce-ejbd.v6.2.557 :
Posted: Fri Jan 08, 2016 2:34 pm
by aazizi.tarik
The explanation says:
you must use the full name i.e. java:comp/env/com.enthu.ejbplus.TellerBean/manager and for EJBContext you must use the relative name i.e. com.enthu.ejbplus.TellerBean/manager
I think it should better be:
you must use the full name i.e. java:comp/env/com.enthu.ejbplus.TellerBean/manager and for EJBContext you
may use the relative name i.e. com.enthu.ejbplus.TellerBean/manager
Because EJBContext can also use the full name