aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Session EJB 3.1 inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Session EJB 3.1 inheritance" Watch "Session EJB 3.1 inheritance" New topic
Author

Session EJB 3.1 inheritance

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Howdy!

I would like to know if it's advised to extend a session EJB? What about the SessionContext, EntityManager? Will those be the same in the supreclass and in subclass or can the container inject different objects for the inherited class?


EJB 3.1 specification, 4.9.2.1 Session Bean Superclasses wrote:A session bean class is permitted to have superclasses that are themselves session bean classes. However, there are no special rules that apply to the processing of annotations or the deployment descriptor for this case. For the purposes of processing a particular session bean class, all superclass processing is identical regardless of whether the superclasses are themselves session bean classes. In this regard, the use of session bean classes as superclasses merely represents a convenient use of implementation inheritance, but does not have component inheritance semantics.

As an example, the client views exposed by a particular session bean are not inherited by a subclass that also happens to define a session bean.



Assuming Foo and Bar are local business interfaces and there is no associated deployment descriptor, session bean A exposes local business interface Foo and session bean B exposes local business interface Bar, but not Foo. Session bean B would need to explicitly include Foo in its set of exposed views for that interface to
apply. For example:



I can deal with the explicitly implementing the interface as in the example - that's not the problem.
If I understand it correctly - there will be TWO EJB's created - one that is the superclass and the other that is the subclass (both will be accessible i.e. through their remote interfaces).

I just wonder what about the transactions, thread-safety and EntityManager safety... Do you think such implementation reusing is allowed and advised or should rather be avoided?

Thanks in advance!

Cheers!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10289
    
168

Pedro Kowalski wrote:Howdy!

I would like to know if it's advised to extend a session EJB? What about the SessionContext, EntityManager? Will those be the same in the supreclass and in subclass or can the container inject different objects for the inherited class?


The super class being a bean or not is irrelevant for a subclass bean. Like the example you posted, even if the subclass extends another EJB, it doesn't change it's behaviour when it comes to transactions and other EJB semantics. To make it more clear:






has the same semantic as:






(notice that I removed @Stateless from SuperBean).

So the fact that SuperBean itself is a bean doesn't make any difference for the ChildBean.

[My Blog] [JavaRanch Journal]
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Thanks a lot Jaikiran for your time and explanation.

That's pretty awesome feature of EJB's!

Thanks once again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session EJB 3.1 inheritance