• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session EJB 3.1 inheritance

 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Jaikiran for your time and explanation.

That's pretty awesome feature of EJB's!

Thanks once again!
reply
    Bookmark Topic Watch Topic
  • New Topic