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

Moderator: admin

Post Reply
supergiu
Posts: 8
Joined: Thu Sep 25, 2014 2:48 pm
Contact:

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

Post 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

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

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

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

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

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

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

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

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

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

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

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

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

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

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

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

lveto15
Posts: 27
Joined: Tue Sep 22, 2015 1:01 pm
Contact:

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

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

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

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

Post by admin »

Injection is ok. By writable they mean modifying its value through your code.
If you like our products and services, please help us by posting your review here.

lveto15
Posts: 27
Joined: Tue Sep 22, 2015 1:01 pm
Contact:

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

Post 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 :).

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

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

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

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests