Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

MDB and its strange inheritance

 
thuy nguyen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cut and paste this paragraph from the specification:

The message-driven bean class may have superclasses and/or superinterfaces. If the message-driven
bean has superclasses, the methods of the message listener interface, lifecycle callback interceptor
methods, the timeout method, the ejbCreate method, and the methods of the MessageDriven-
Bean interface may be defined in the message-driven bean class or in any of its superclasses. A message-
driven bean class must not have a superclass that is itself a message-driven bean class

Since a MDB can not subclass another MDB, it can only subclass a POJO. It is strange that a POJO can have
"the methods of the message listener interface, lifecycle callback interceptor methods, the timeout method, the ejbCreate method, and the methods of the MessageDriven-Bean interface"
 
Michael Antonov
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thuy nguyen wrote:I cut and paste this paragraph from the specification:

The message-driven bean class may have superclasses and/or superinterfaces. If the message-driven
bean has superclasses, the methods of the message listener interface, lifecycle callback interceptor
methods, the timeout method, the ejbCreate method, and the methods of the MessageDriven-
Bean interface may be defined in the message-driven bean class or in any of its superclasses.
A message-
driven bean class must not have a superclass that is itself a message-driven bean class

Since a MDB can not subclass another MDB, it can only subclass a POJO. It is strange that a POJO can have
"the methods of the message listener interface, lifecycle callback interceptor methods, the timeout method, the ejbCreate method, and the methods of the MessageDriven-Bean interface"

That is not strange really. You can create a POJO superclass, which has onMessage method, and which is implementing the appropriate interface, say MessageListener.
That you create just a empty class which subclasses your superclass, has @MessageDriven annotation, and no onMessage method. This is valid. onMessage method for MDB will be picked up from superclass.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!