• 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic