0

As I can understand, @Localbean on an EJB is used when one doesn't want to define any interface for the EJB. Then I saw many websites, including IBM1, that show something like this:

@Stateless
 @Local(LocalA.class)
 @Remote(RemoteA.class)
 @LocalBean
 public class MeineEJB {
     public void localA() {}
     public void remoteA() {}}

If it is a no-interface EJB, then what is the useage of @Local(LocalA.class) in this code? (I assume that it is an interface.) And also, I don't understand @LocaBean and @Remote at the same time. @LocalBean says it is a local bean, but we defined it as a remote as well. Then why the annotation title is @LocalBean at the first place?

Thanks for reading folks.

Kawe
  • 51
  • 7
  • 1
    This is covered quite well in https://stackoverflow.com/questions/10889563/ejb-3-1-localbean-vs-no-annotation. And yes, having both local, remote and localbean seems a bit pointless. Combining remote and localbean could make sense. – ewramner Mar 07 '19 at 10:57
  • I appreciate your response @ewramner. I have seen that link before asking this question and it does not answer my question. I would be grateful if you could take a look at IBM link I sent, or the end of the page in this link. It looks like they define an interface as well. https://www.javacodegeeks.com/2013/03/defining-ejb-3-1-views-local-remote-no-interface.html – Kawe Mar 07 '19 at 12:11
  • Both your links are examples where they show what is possible with EJB 3.1, not what is best practice. The examples must work, but they don't have to make sense. The same bean is exposed with a local no-interface view, a local interface view with LocalA and a remote interface view with RemotA. It is possible. Is it common? Probably not, I haven't seen it. Exposing local and remote is common, but not all three. – ewramner Mar 07 '19 at 12:56
  • Thank you @ewramner. Now the examples make sense to me. – Kawe Mar 07 '19 at 16:10
  • Possible duplicate of [EJB 3.1 @LocalBean vs no annotation](https://stackoverflow.com/questions/10889563/ejb-3-1-localbean-vs-no-annotation) – Steve C Mar 17 '19 at 03:52

1 Answers1

1

You're just being confused about why @Local & @LocalBean are annotated on the same MeinjeEJB class. And not specifically on their differences.

The no-interface (@LocalBean) is nothing but a variation of the local view that exposes all public business methods of the bean class locally without the use of a separate business interface.

In EJB it's possible to expose an interface as a Local(i.e clients are running in the same JVM - Servlet, JSF, another EJB) interface, Remote (i.e clients are RMI, other forms of RPC, etc) interface, or No-interface view (implements no interface). I.e :

@Stateless 
@Local(LocalA.class) @Remote(RemoteA.class) 
@LocalBean 
public class MeineEJB { 
public void localA() {}
 public void remoteA() {}}

If the bean exposes at least one interface (local or remote) it will automatically loses the no-interface view. So we needs to explicitly specify that it exposes a no-interface view by using the @LocalBean annotation on the bean

Note : Don't confuse @Local & @LocalBean on the MeinjeEJB class. We need @LocalBean because MeineEJB will be invoked locally (i.e. cannot be invoke remotely) by clients (JSF, Servet, etc.). What will be invoked remotely is the RemoteA.class by the MeineEJB itself.

Fevly Pallar
  • 3,059
  • 2
  • 15
  • 19