About Question enthuware.oce-ejbd.v6.2.557 :

Moderator: admin

Post Reply
zoot11
Posts: 2
Joined: Wed Dec 04, 2013 4:57 am
Contact:

About Question enthuware.oce-ejbd.v6.2.557 :

Post 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?

admin
Site Admin
Posts: 10228
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.557 :

Post 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.
If you like our products and services, please help us by posting your review here.

zoot11
Posts: 2
Joined: Wed Dec 04, 2013 4:57 am
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.557 :

Post 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!

admin
Site Admin
Posts: 10228
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.557 :

Post 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.
If you like our products and services, please help us by posting your review here.

vinkjrwl
Posts: 7
Joined: Sat Feb 08, 2014 8:30 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.557 :

Post 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?

admin
Site Admin
Posts: 10228
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.557 :

Post 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.
If you like our products and services, please help us by posting your review here.

aazizi.tarik
Posts: 31
Joined: Sun Dec 27, 2015 1:47 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.557 :

Post 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

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests