wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Session beans must not be final doubt. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Session beans must not be final doubt. " Watch "Session beans must not be final doubt. " New topic
Author

Session beans must not be final doubt.

Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
EJB In Action 3.0 Page: 78:
Programming Rules:
Do not mark Session bean implemention class as final.

Result:
23:42:48,796 INFO [EJBContainer] STARTED EJB: com.ejb3inaction.actionbazaar.buslogic.PlaceBidBean ejbName: PlaceBidBean
23:42:48,937 INFO [EJB3Deployer] Deployed: file:/E:/DJ/Java Certifications/SCBCD/eBooks/Application Servers/JBOSS/jboss-4.2.3.GA/server/default/tmp/deploy/tmp2446myEJB.ear-contents/myEJB-ejb.jar
23:37:32,312 INFO [STDOUT] Adding bid. bidder ID=20091297,item id=22 , bid amount=200.0

It worked fine. Is the statement in EJB Action correct, if not what is it trying to convey?

EJB Specification:
The class must be defined as public, must not be final, and must not be abstract. The class must be a top level class.


SCJP, SCWCD, SCBCD
aleem khan
Ranch Hand

Joined: Aug 07, 2008
Posts: 94
They are trying to convey here that "You should not make the class as final as a good practice" infact even if you make final there will not be any error but you may not be able to subclass it because of "final"...i think it is just like a good practice/design ........ I dont think think there is any EJB Container which will throw the error if you make class as final , if it does then it is contradicting with Java concepts... It will throw error only when you try to subclass the "final class" (using extend keyword)...i hope i am clear in this explanation


SCJP(1.4), SCWCD, Oracle 9i SQL certified, Oracle PLSQL Developer Certified Associate
Mellon Sun
Ranch Hand

Joined: Feb 20, 2003
Posts: 126
I tried in NetBeans6.5+GlassFishV2, it works if a stateless session bean declared as final.

I don't think "must not" means "you'd better". NetBeans burst a warning massage "EJB cannot be final", unfortunately the bean still compiled and works. I prefer treating it as immature of the container like GlassFish.

By the way, I wanna know why EJB must not be final since it can works as final.


SCJP,SCWCD1.3,SCWCD1.4,SCJD,SCBCD5,SCEA5
Chandrashekhar Raiphale
Greenhorn

Joined: Aug 26, 2006
Posts: 14
I tried with Eclipse + Weblogic and got following error on server console:


Unable to deploy EJB: sims.ejb.TestSB

Cannot inherit from final class


Cheers,<br />Chandrashekhar <br />SCJP
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Appreciate your responses.
The specs clearly states bean class "MUST NOT". I want to know what are the consequences of doing so?
Is the consequence vendor specific. I am using notepad+JBOSS, I did not receive any warnings or errors or exceptions @ compile or runtime.

Please elaborate.
Chandrashekhar Raiphale
Greenhorn

Joined: Aug 26, 2006
Posts: 14
there was no compilation error as such but when i started server i got the Exception on server log, which i wrote in my pevious post.
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Does that mean that the behavior is application server vendor specific.
The spec only uses the words "MUST NOT" and does not say anything as to what will happen if a session bean is declared as final.

If you would have my other posts you would have noticed that I have found similar issues where the session beans are clearly violating the rules of Session Beans.

For Session Beans rules i have read EJB In Action 3.0
Application Server: JBOSS 4.2.3.GA
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Deepak,

Sorry for the delay in replying...just came back from vacation.

The implementation you are using appears to be non-compliant.

Best regards,
Reza


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
One more....
The code was deployed with jboss-4.2.3.GA application server.

Looks like one must not use jboss-4.2.3.GA.
Please suggest a better application server which is completely compliant with ejb 3.0 specification

I think we need to put these similar cases in SCBCD FAQ, if its not there already.
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Deepak,

Please see my earlier post on a similar thread you started.

Best regards,
Reza
Mark Garland
Ranch Hand

Joined: Nov 11, 2006
Posts: 226
Hi,

Just wanted to say thanks to everyone for the answers in this thread.
I was just reading p78 myself, thought "wonder why not final...?" then found this thread.

I can understand the bit about being public, having a no arg constructor, not being abstract... as each of these things could prevent the container from instantiating your bean. But final?
I read this thread as saying "the spec says MUST NOT", but I'm still not clear as to why - unless it is just "good practice"?
Why stop there - why not mandate in the spec that we must also comment our beans...?


Thanks,

MG


28/06/06 - SCJP - 69%, 05/06/07 - SCWCD - 92%, 28/02/08 - IBM DB2 v9 Fundamentals (Exam 730) - 87%, 18/11/08 - IBM DB2 v9 DBA (Exam 731) - 89%, 26/02/11 - SCBCD - 88%
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Mark,

The issue here is that some containers may need to sub-class your bean (not all containers mind you). It's a restriction to give containers implementors some choices.

Regards,
Reza
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session beans must not be final doubt.
 
Similar Threads
Need Help while running stateless session bean with Servelet bean client
A session bean class must not have a superclass that is itself a session bean class.
hoq to make EJB interface using Netbeans
Business method names must not start with "ejb".
Multiple postconstruct and predestroy methods.