I understand the difference between local view, remote view and no-interface view. I just don't understand what is the difference between "no view" (no annotation) and no-interface view. And also why should I annotate my interface with @Local
? What if I don't annotate the interface in at all, is there a difference?

- 10,145
- 15
- 56
- 70

- 1,960
- 4
- 20
- 27
-
What kind of EJB bean would it become if you don't annotate it all? Or to put it differently, how would the container know if a class was a POJO or a SessionBean? – esej Jun 04 '12 at 23:09
-
2@esej You annotate it with Stateless, Stateful or Singleton annotation and then you either annotate it with Local, Remote or LocalBean annotation or you don't annotate it with this kind of annotation. So the container know if a class is a SessionBean when you annotate it with either Stateless, Stateful or Singleton annotation. – VaclavDedik Jun 04 '12 at 23:30
-
Correct. (Earlier I failed to see what you thought the difference would be, now I've grown wiser (cause I had a strange idea).) – esej Jun 04 '12 at 23:42
-
I think the absence of an annotation implies a no-interface view. So there isn't a difference between "no view" and a no-interface view! – Tom Anderson Jun 05 '12 at 10:46
3 Answers
The rules are (from memory):
- Bean has a
@LocalBean
annotation -> bean has a no-interface view - Bean has a
@Local
annotation -> bean has a local view - Bean has a
@Remote
annotation -> bean has a remote view - Bean has no view annotations, but directly implements an interface which has a @Local annotation -> bean has a local view
- Bean has no view annotations, but directly implements an interface which has a @Remote annotation -> bean has a remote view
- Bean has no view annotations, but directly implements an interface which has no view annotations -> bean has a local view
- Bean has no view annotations, and implements no interfaces -> bean has a no-interface view
So, using @LocalBean
and using no annotation at all are both ways of getting a no-interface view. If you just want a no-interface view, then the simplest thing is not to annotate. Provided you're not also implementing any interfaces.
Part of the reason @LocalBean
exists to add a no-interface view to a bean which also has an interface view. I imagine the scenario uppermost in the spec authors' minds was one where you have a bean like:
@Stateless
public class UserPreferences {
public String getPreference(String preferenceName);
public Map<String, String> getPreferences();
}
Where you would want to expose both methods locally, but only the coarser-grained getPreferences()
remotely. You can do that by declaring a remote interface with just that method, then just slapping @LocalBean
on the bean class. Without it, you'd have to write a pointless local interface just to expose both methods locally.
Or, to look at it another way, the @LocalBean
exists because there is such a thing as a no-interface view, and the no-annotation option exists as a handy shortcut.

- 46,189
- 17
- 92
- 133
-
9The exact rules are in section 4.9.7 of the EJB 3.1 spec. They are slightly more complicated than what you present (homes, webservices, java.io/javax.ejb interface exclusions), but this is a nice summary. – Brett Kail Jun 05 '12 at 12:08
-
@bkail: Thanks for the reference. I don't have a copy of the spec handy, and Oracle's site ground to a halt when i tried to download one, so i couldn't check. I have realised that this is an area i need to read up on, though! – Tom Anderson Jun 05 '12 at 12:16
-
-
@bitli: If the POJO does not implement any interfaces, and has no annotations, then it has a no-interface view, just as if it was annotated with `@LocalBean`. – Tom Anderson Mar 31 '14 at 10:59
- Remote EJBs: can be accessed from remote clients (clients running on a different JVM such as Swing or JavaFX clients which run on the user machine)
- Local EJBs: can only be access from other "components" running on the same JVM, e.g. Web Front-ends, other EJBs
- No-interface view: same as Local but without specifing the business interface
- No annotation: a simple POJO but not an EJB
Local/ No-interface views are more efficient than remote EJBs, since objects references can be passed around.

- 37,247
- 13
- 80
- 152
-
2I thought that a POJO becomes EJB when you annotate it with Stateless, Statefull or Singleton annotation. Am I missing something? – VaclavDedik Jun 04 '12 at 23:25
-
1@Puce, You said "No annotation: a simple POJO but not an EJB", which contradicts Tom Anderson's comment "If the POJO does not implement any interfaces, and has no annotations, then it has a no-interface view, just as if it was annotated with @LocalBean". Can you clarify? – bigfoot Apr 26 '18 at 03:50
I think that the confusion you/we are feeling is a result of history / backwards compitability (so to speak). I can't dicern any difference (except that the spec. requires implementations to create an interface if we use local-view)
The no-interface view has the same behavior as the EJB 3.0 local view, for example, it supports features such as pass-by-reference calling semantics and transaction and security propagation. However, a no-interface view does not require a separate interface, that is, all public methods of the bean class are automatically exposed to the caller. By default, any session bean that has an empty implements clause and does not define any other local or remote client views, exposes a no-interface client view.

- 3,059
- 1
- 18
- 22