• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is a CreateException in the method-declaration necessary?

 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Paul Sanghera wrotes in his book, that it is not necessary to declare a CreateException in the throws-clause of ejbCreate() and ejbPostCreate(), if you do not explicitly throw a CreateException in your code.

Hence I have removed all CreateExceptions from ejbCreate() and ejbPostCreate(). After that, I have deployed my beans again in JBoss, and now I will get the following warnings:

WARN [verifier] EJB spec violation:
Method : public RecipePosPK ejbCreate(int, RecipePos)
Section: 10.6.4
Warning: The throws clause must define the javax.ejb.CreateException.

Must I declare javax.ejb.CreateException in the throws-clause of ejbCreate() and ejbPostCreate(), even if I do not throw this exception?

Regards,
Oliver
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJB 2.0 Spec:

Chapter 7 Session Bean Component Contract
7.10.3 ejbCreate<METHOD> methods
The throws clause may define arbitrary application exceptions, possibly including the
javax.ejb.CreateException.


Chapter 10 Entity Bean Component Contract for Container-Managed Persistence
10.6.4 ejbCreate<METHOD> methods
The throws clause must define the javax.ejb.CreateException. The throws clause may define arbitrary application specific exceptions.


Chapter 12 Entity Bean Component Contract for Bean-Managed Persistence
12.2.3 ejbCreate<METHOD> methods
The throws clause may define arbitrary application specific exceptions, including the
javax.ejb.CreateException.


So the CMP Entity Bean ejbCreate and ejbPostCreate have to specify the CreateException in the throws clause.
Session Bean and BMP Entity Beans may specifiy it.
 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peer, thanks again for your great help.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interestingly I also just yesterday ran across this little tidbit in Monson-Haefel's Enterprise JavaBeans 4e (p.78):

Although it's not required by the EJB specification, some J2EE application vendors insist that ejbCreate() throw a javax.ejb.CreateException - this is true of the J2EE 1.4 SDK. This has never been a requirement, but it's an issue that continues to crop up every time there is a new edition of the book.
 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's good to know. I think, especially for my SCBCD-preparing, I should not rely on the behavior of JBoss.

Peer, with your excellent knowledge about EJB you should get a high-score in the exam!
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • True, you cannot rely on any particular implementation. However in this particular case JBoss was correct. Did you notice that it actually cited the relevant section in the spec (10.6.4)?
  • Well, actually I'm still looking a lot of this stuff up - however I do usually find it easier to locate something in the spec and understand the spec once I've digested a study guide.

  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic