Page 1 of 1

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

Posted: Thu Sep 25, 2014 2:52 pm
by supergiu
Sorry but in my opinion in this snippet:

Code: Select all

@Remote(SfSBeanRemote.class) 
public class SfSBean implements SfSBeanRemote {
    //valid code... 
}  

public interface SfSBeanRemote  {     
void processData(); 
}
in bean declaration, there must be a session type annotation (@Stateless, @Stateful, @Singleton).

Thanks

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

Posted: Fri Sep 26, 2014 12:15 am
by admin
Why do you think there has to be a session type annotation? It could be specified in the deployment descriptor xml as well. The question doesn't rely on the session type of the bean.

HTH,
Paul.

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

Posted: Tue Apr 28, 2015 1:15 pm
by himaiMinh
For option 3

Code: Select all

@EJB static SfSBean sfs 
,

will it be possible if:
1. the client in .war/.jar is packaged in the same .ear file as that
.jar file containing the SfSBean and the client include that .jar in the classpath ?

2. the client has SfSBean.class in its classpath ?

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

Posted: Tue Apr 28, 2015 7:55 pm
by admin
Yes, if the client is in the same jar as the the bean, then you can use SfSBeanRemote.
Just being in classpath is not enough. Local interface can be used only if the client and the bean are in the same container.

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

Posted: Wed Apr 29, 2015 9:44 am
by himaiMinh
Hi admin,
So, in this mock exam question, it is assumed that the client is a standalone client in a different container where the bean resides ?

In this question, the bean is exposed as a remote view. So, I believe the bean cannot be injected as a no-interface view.
That means:

Code: Select all

//it works
@EJB
SfsBeanRemote remoteViewOfBean;
but

Code: Select all

//it won't work as this bean only exposed as a remote view according to this question.
@EJB 
SfsBean noInterfaceViewOfBean;

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

Posted: Wed Apr 29, 2015 2:55 pm
by himaiMinh
Let me answer my own question.
In the question , there are two ways to inject a remote bean @EJB or @EJB (name=...).
This remote bean should be in the same container as the client.

If the remote bean is in a different container as the client, we should do this to look up a bean:
@EJB (lookup="java:global/appName/moduleName/SfSBean!SfsBeanRemote").
Or, the client is in a different application (a different .ear file for example), we have to use the lookup attribute.

Correct me if I am wrong.

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

Posted: Sun Jul 03, 2016 9:30 am
by lveto15
Isn't this question a bit incorrect? According to spec 21.2.2:
An enterprise bean must not use read/write static fields. Using read-only static fields is allowed. Therefore, it is recommended that all static fields in the enterprise bean class be declared as final.
using writable static field is forbidden. Injection is kind of writing, so it shouldn't work.

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

Posted: Sun Jul 03, 2016 9:53 am
by admin
Injection is ok. By writable they mean modifying its value through your code.

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

Posted: Sun Jul 03, 2016 10:24 am
by lveto15
I understand explanation but cannot make it works. In my example sfs is null till I have removed static (of cause also must change the main method). I know that questions during exam are tricky. This one is special one :).

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

Posted: Sun Jul 03, 2016 10:51 am
by admin
It should work. Also, the given code is not of an EJB that is using a static field. It some application class, which is running inside an application client container.