Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CreateException

 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Referring to the EJB 2.0 Spec on Session Beans...

--------------------------
7.10.3 ejbCreate<METHOD> methods

The throws clause may define arbitrary application exceptions, possibly including the javax.ejb.CreateException.


7.10.6 Session bean's remote home interface

The throws clause must include javax.ejb.CreateException.
------------------------------


Referring to the EJB 2.0 Spec on Entity Beans...

-------------------------------
10.6.4 ejbCreate<METHOD> methods

The throws clause must define the javax.ejb.CreateException.


10.6.10 Entity bean's remote home interface

The throws clause of a create<METHOD> method must include the javax.ejb.CreateException.
----------------------------------------


It is a MUST for create() in home interface but NOT A MUST for ejbCreate() in the Bean. Why ?
Isn't that all application exceptions must match between
create and ejbCreate,
remove and ejbRemove and
find and ejbFind ?


This issue struck me when I saw that on page 268 of HF-EJB does not have a CreateException for its ejbCreate in the CustomerBean EB.


To add to my confusion, in the Spec :
------------------------------
10.7.3 ejbFind<METHOD> methods

The throws clause must define the javax.ejb.FinderException.
------------------------------
but on the same page of HF-EJB, those ejbFind<methods> do not throw !


Please clarify. Thanks !!!
 
Shiang Wang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CreateException and FinderException are application exception, unless you throw them in the method, you can't declare them. Compiler will not pass.

Entity bean is the only bean that requires ZERO or more create method. You have to have create method in the home, hence no need in entity bean class. Plus create in entity bean works like insert. If you don't want users to be able to insert records to the database, it makes sense without create method. Does that answer your question ?

Shiang
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[CreateException and FinderException are application exception, unless you throw them in the method, you can't declare them. Compiler will not pass.]

I think this statement of yours is incorrect. I have written a small program to prove it.




NoSuchFieldException is a Checked Exception/App Exception. It extends java.lang.Exception.

Although my method go() declares NoSuchFieldException but does not throw it, it compiles (and runs) fine.

[ December 22, 2004: Message edited by: Timothy Toh ]

[ December 22, 2004: Message edited by: Timothy Toh ]
[ December 22, 2004: Message edited by: Timothy Toh ]
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still don't understand why

SB:
ejbCreate in bean - POSSIBLY INCLUDING the javax.ejb.CreateException.
create in home - MUST include javax.ejb.CreateException.

Thanks.
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody give me a clue ?

I don't have problem with EB... since create methods in both home and bean are mandatory.

My problem is with SB.

Thanks.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is just a grammatical problem. You have to know that the EJB spec has undergone three different releases (1.0, 1.1, 2.0 and now 2.1) and updates might not always be 100% accurate and correct. I would not focus on that too much, just declare CreateException in the ejbCreate() signature and you'll be well off

Your next question might be "what if the exam asks whether it is mandatory to declare CreateException in the throws clause of the ejbCreate() method of session bean?" and I would answer that the options will be formulated in a way that makes it clear what the correct answer is
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crettaz, Thanks.

Will not let a possible grammar mistake screw me up.

 
Shiang Wang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timothy:

I agree with Valentin, just move on with other subjects. I myself experienced subtle differences in the spec and Weblogic, JBoss.
One thing you can relex is there are no ambiguious questions in the real exam. Almost every question, you know what its intention is for.

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