Can an EJB bean implement multiple interfaces?
Asked Answered
L

1

7

Can an EJB bean implement multiple user defined interfaces, except business interfaces (@Local, @Remote) or No-Interface view (@LocalBean)?

For example define two interfaces UserInterface1, UserInterface2, with no annotation.

Is this legal to implement:

@Stateless
public class MyBean implements UserInterface1, UserInterface2 { ...

Then I have another confusion:

@Stateless
public class MyBean implements Runnable { ...
//inside I won't try to manage thread
}

Is this legal or illegal, I found that glassfish support this situation.

Landtag answered 21/12, 2012 at 7:48 Comment(0)
W
6

The given example is illegal, but nevertheless accepted by quite some implementations (application servers).

David Blevins started a thread about this on the EJB mailing list a while ago.

EJB 3.2 will make the rules more clear for this topic. See What's new in EJB 3.2 ? - Java EE 7 chugging along! (look for section Simplified the rules to define all local/remote views of the bean)

Wrestle answered 21/12, 2012 at 10:34 Comment(5)
what if I just implement one interface (still without any annotation)? That interface could be user defined or interface from some java packages(for example java.lang.) is this implementation illegal?Landtag
1 interface seems to be legal without using any annotations. See docs.oracle.com/javaee/6/api/javax/ejb/Local.htmlWrestle
The answer is good, though it doesn't answer the topic question, to which I would respond, "yes, an EJB can implement multiple interfaces, but in that case, you must explicitly specify which interfaces are business interfaces using @Local or ejb-jar.xml".Lyndalynde
@bkail the topic title says "multiple interfaces", but the post opens with asking for multiple interfaces, except business interfaces. Unfortunately the situation with mixing (multiple) business interfaces and (multiple) regular interfaces is not that clear.Wrestle
Even considering David's post, the semantics seem quite clear when (non-empty) @Local is specified on the bean class. Anyway, if OP is satisfied, that's all that matters :-).Lyndalynde

© 2022 - 2024 — McMap. All rights reserved.