• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Throw CreateException in callbacks

 
George Zou
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can ejbCreate method throw CreateException?
Seems HFE book contradict itself on this issue.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session beans (7.10.3):
The throws clause [of the ejbCreate method of a session bean] may define arbitrary application exceptions, possibly including the javax.ejb.CreateException.

Entity beans (10.6.4):
The throws clause [of the ejbCreate method of an entity bean] must define the javax.ejb.CreateException. The throws clause may define arbitrary application specific exceptions.

Message-driven beans (15.7.3):
The throws clause [of the ejbCreate method of a message-driven bean] must not define any application exceptions.
 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Valentin Crettaz:
[QB]Entity beans (10.6.4):
The throws clause [of the ejbCreate method of an entity bean] must define the javax.ejb.CreateException. The throws clause may define arbitrary application specific exceptions.QB]


An entity bean's ejbCreate must throw a javax.ejb.CreateException?

I was under the impression that either an entity or session bean can throw them by declaring them, but don't need to if they don't throw them.

Does this mean ejbPostCreate must also throw a javax.ejb.CreateException?

Thanx for the help.

James.
 
Sandesh Tathare
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
10.6.5 ejbPostCreate<METHOD> methods
The throws clause may define arbitrary application specific exceptions, including the javax.ejb.CreateException.
 
Mohammed Eesa
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never see any ejbCreate() methods throws CreateException.But
spec says that "entity beans ejbCreate() must throw CreateException".
Can any one explain me clearly.
 
Yi Zou
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the book Head First EJB:
Page 545: Dumb Question No.1 it says The only thing you can throw in callbacks is EJBException.
Page 547: Scenarios No.3, it ask what to do if you throw CreateException in ejbCreate().

CreateException extends Exception, not a runtime execption.

Anyone clear this?
 
Nileesha Bojjawar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A CreateException is a Application Exception and a checked Exception which should be propogated as it is to the client.
The container callbacks are the ones invoked by the container but if the callback is invoked because of a direct invokation ofa method by the client , it can throw any defined application Exceptions.
For Eg: ejbActivate() is a container callback in which there is not client context and container decides if it need st oactivate a bean and hence if you are doing anything in this method implementation and catch a exception you can only throw a runtime Exceptione ie EJBException.
Hope this helps.
 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when you declare an ejbCreate method for an entity bean you must always declare it throws a javax.ejb.CreateException?

With ejbCreate's of other beans you may declare it throws a javax.ejb.CreateException if you want?

Is that correct?

Or can you declare a javax.ejb.CreateException only if you need to, even for entity beans?

Thanx for the help.

James.
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

One need to pay attention to the difference between the rules for CMP eb and BMP eb

Container-Managed Persistence Entity beans' ejbCreate (10.6.4):
The throws clause must define the javax.ejb.CreateException. The throws clause may define arbitrary application specific exceptions.


Bean-Managed Persistence Entity beans' ejbCreate (12.2.3):
The throws clause may define arbitrary application specific exceptions, including the javax.ejb.CreateException.



 
Mohammed Eesa
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CMP Beans is working fine eventhough,i am not declare any throws clause[CreateException] in ejbCreate().but spec say "you must throw ..."
 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Head First EJB book says you may declare to thow a CreateException in the ejbCreate of an entity bean. The spec says you must. But I have seen other book use entities without throwing a CreateException in the ejbCreate method (Mastering EJB 2).

I think the spec may have a mis-typing...

James.
 
Sandesh Tathare
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Valentin,


Entity beans (10.6.4):
The throws clause [of the ejbCreate method of an entity bean] must define the javax.ejb.CreateException. The throws clause may define arbitrary application specific exceptions.


On page no. 333 of HF EJB it clearly says

You may declare throws clause with CreateException, or any arbitary application (checked) exceptionthat you like, as long as it was also declared in the home interface, but you must NOT declare a RemoteException.


:roll:
Now please clarify for God sake, which one is correct? HFEJB or Specs?
Please please... I got exam in coming week. Hurry up.
 
Paulus Maessen
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandesh,

I would definitely go for the spec.

Maybe it's a missprint in HF EJB: because for sessionbeans you are indeed not required to include CreateException...
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The spec is right!!

In HFEJB, this was *my* mistake -- that you *may* declare it. This is how it was with the *previous* version of EJB, and I somehow missed that part of the change in the spec, *especially* since most Containers will let you get away *without* declaring it. But... the J2EE 1.3 RI will FORCE you to do the declaration.

Anyway, the spec is right--for CMP entity beans, you MUST (not MAY) declare the exception.

Sorry about that.

I would ALWAYS assume that the spec is correct in this case, although the spec can sometimes be tricky to read because it will not always tell the whole story in one particular section. Sometimes you have to read several sections to put together the complete story. In other words, you might read a set of rules on one page, but they do not include ALL rules related to that thing... and you might have to wait until you get to another part of the spec before you see *new* rules that add more detail.

But this one was simply my mistake. Not even a *typo*; I actually BELIEVED this to be true because it was true in the past, and I missed this change in the 2.0 spec.

Again, SORRY!!

And my apologies that I haven't been here much to answer questions--we're still in the first printing of the SCWCD book, and there aren't as many people in that forum who can answer the questions the way folks HERE can answer one another's questions, so I've been spending more time over there.

Thanks to all who have been so helpful here.

cheers,
Kathy
 
Sandesh Tathare
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Kathy for clarification. We all understand work load on you.

And I must thank all guys and gals who are doing a gr8 job by posting replies on this forum.
 
George Zou
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank Kathy for clearify.
I passed the exam using the book anyway:-) I guess the book itself is good enuf to pass.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic