• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Subclassing rules for Session beans

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example, I have a Local interface as,



And the implementation class which is a stateless bean like,





Can anyone explain me on the Annotation inheritance?
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It won't work. As per the specifications, you cannot inherit from a superclass which itself is a session bean.
[ June 14, 2008: Message edited by: nitin pai ]
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the specs...is ok but I read in the book EJB 3 in Action on Subclassing rules for Session beans?? Here is what it says...

A session bean class can subclass another session bean or any other POJO.
For example, a stateless session bean named BidManager can extend
another session bean PlaceBidBean in the following way:
@Stateless
public BidManagerBean extends PlaceBidBean implements BidManager {
...
}

 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quoting from the spec section 4.6.2, 6th point in "Optionally"

The session bean class may have superclasses and/or superinterfaces. If the session bean has
superclasses, the business methods, lifecycle callback interceptor methods, the timeout callback
method, the methods of the optional SessionSynchronization interface, the
Init or ejbCreate<METHOD> methods, the Remove methods, and the methods of the
SessionBean interface, may be defined in the session bean class, or in any of its superclasses.
A session bean class must not have a superclass that is itself a session bean class.



Books can have mistakes, but certification will be based on specification.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by nitin pai:
Quoting from the spec section 4.6.2, 6th point in "Optionally"



Books can have mistakes, but certification will be based on specification.



Thanks Nitin. Any reason why we can't have a session bean as another session bean's superclass?
 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may be possible that your session bean is stateless and you unknowingly extend it with a session bean which is stateful. The behavior of your application will be weird then, don't you think so?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried this on Glassfish :


The client :


It's funny that it worked
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So Nitin, did the specs go wrong?
 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jothi Shankar Kumar Sankararaj:
So Nitin, did the specs go wrong?



Do you even know what specs means?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by nitin pai:


Do you even know what specs means?



I know what specs mean...I doubt you practically know anything as it looks like you just follow something that's written somewhere (like specs) and then just post it here in the ranch as though you tried it.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Christophe Verre:
I tried this on Glassfish :


The client :


It's funny that it worked



Any takers on this?
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jothi,

I am with nitin on this one: the specification is the law. You'll be asked about the specification, not any particular implementation (not even the reference implemetation).

However, just out of curiosity, what happens when you try this?



In the client:


Please, post results. :-)
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't be fooled by my sample. I only mean that the book said that it would work because they may have tried it on a container supporting it, but the specs are the specs. If they tell that it does not work, then it doesn't. If it does, it's container specific and should not be relied on.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sergio, in your example, how would you call doSomething on a SimpleBean ?
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Christophe Verre:

Sergio, in your example, how would you call doSomething on a SimpleBean ?



Sorry. My mistake. I meant something like:
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that specs is like E=mc^2 for Java/J2EE technologies. But from the lines what nitin has posted mentioning the specs, I thought that there would be a mention somthing like..."It is up to the container vendors...." so is our case similiar to that? As per the specs, a session bean cannot subclass another session bean but it is up to the vendors to make subclassing session bean possible.
[ June 27, 2008: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
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

Originally posted by Jothi Shankar Kumar Sankararaj:
I thought that there would be a mention somthing like..."It is up to the container vendors...." so is our case similiar to that? As per the specs, a session bean cannot subclass another session bean but it is up to the vendors to make subclassing session bean possible.



Jothi,

You are right, in some cases the specs leave it to the vendors to decide how they deal with certain things. But in this case the spec states that:

A session bean class must not have a superclass that is itself a session bean class.



So if Glassfish is allowing the superclass itself to be a session bean, then i would say that its a bug in Glassfish server, since its not following the specs.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jaikiran Pai:


So if Glassfish is allowing the superclass itself to be a session bean, then i would say that its a bug in Glassfish server, since its not following the specs.



Thanks and I was thinking in the same lines.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jothi Shankar Kumar


From the specs...is ok but I read in the book EJB 3 in Action on Subclassing rules for Session beans?? Here is what it says...

quote:A session bean class can subclass another session bean or any other POJO.
For example, a stateless session bean named BidManager can extend
another session bean PlaceBidBean in the following way:
@Stateless
public BidManagerBean extends PlaceBidBean implements BidManager {
...
}



Same book (EJB 3 In Action) also says that if parent is a bean then bean annotation is not inherited; but call back (life cycle) annotation, business methods,.... are inherited from parent class.



nitin pai

A session bean class must not have a superclass that is itself a session bean class.



As per spec, parent must not be a bean (session bean), isn't it compile time issue (compiler is allowing to have bean parent)?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interestingly there is a similiar discussion in the Head First EJB book in the chapter for Session Beans (Page 186) which I found to be worth mentioning here.
 
Jaikiran Pai
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

As per spec, parent must not be a bean (session bean), isn't it compile time issue (compiler is allowing to have bean parent)?



Its not a compile time issue. From a Java compiler's perspective, its perfectly valid for one class to extend another. Java compiler has no knowledge of what EJBs are. Its the application server which at deployment time takes care of ensuring that the EJBs follow the specs.
 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In other case, basic rule is a class can not 2 classes;
and if a class extends 2 classes, compiler throws error message.

Are both rules (EJB - SB bean must not extend another SB & a POJO class must not extends 2 POJO classes) comes in to different categories? So that first is okay for compiler but not the second.
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sanjeev, Both are wrong, you cannot have multiple inheritance in Java.

What he was saying is that compiler will have no problem because all session beans are just normal classes to compiler and One class can Extend another class without a problem.

Its only a question of container whether it allows a class which is a session bean to extend another class which is also a session bean, and specs says that is illegal.
 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for reply.
for compiler @Stateless annotation does not make sense;
its container which treats it like EJB.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to bounde back o this topic to get some good clarity, below is what I found from the EJB 3 in Action book,

■ A session bean class can subclass another session bean or any other POJO.
For example, a stateless session bean named BidManager can extend
another session bean PlaceBidBean in the following way:
@Stateless
public BidManagerBean extends PlaceBidBean implements BidManager {
...
}
■ The business methods and lifecycle callback methods may be defined
either in the bean class or in a superclass. It�s worth mentioning here that
annotation inheritance is supported with several limitations with EJB 3 session
beans. For example, the bean type annotation @Stateless or @Stateful
specified in the PlaceBidBean superclass will be ignored when you
deploy the BidManagerBean. However, any annotations in the superclasses
used to define lifecycle callback methods (more about that later in this section)
and resource injections will be inherited by the bean class.



The second bulleted point says that when I fail to mark my subclass bean as @stateless and I deploy my subclass bean, then it is not considered as a bean at all but the life cycle annotations are inherited (the container callbacks). My question is when the class itself is not recognized as a bean then what is the use of inheriting the container callbacks?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic