Originally posted by Roger Chung-Wee:
So, I reckon that the book is correct if you consider an entity bean's ejbCreate() to be a business method. I'm sure that Kathy can explain this better than I ...
Actually, Roger explained it perfectly! What I said in the book *is* confusing, so it isn't your fault it doesn't make sense. As Roger said, there are container callbacks that the client does not see, and there are business methods the client does see. I was treating the create and remove and finders and home business methods as a kind of hybrid-part business method/part callback, but NOT as a *pure* container callbacks. I consider *pure* container callbacks to be ONLY those methods that the client does not see and does not directly trigger.
In other words, the home business methods, finders, create, and remove methods in the bean code DO have slightly different names than the ones the client sees in the interface, but they are still directly triggered by a client call, so we'll still count them as business methods.
Another way to tell that they are business methods and not simply container callbacks is this: pure container callbacks do NOT have transactions specified in the deployment descriptor for a CMT bean.
You can't specify a transaction on something like setSessionContext(), for example. But you DO specify a transaction on create, remove, finders, and home business methods. So that's another way to distinguish the business method callbacks (ejbCreate, ejbRemove, etc.) from the pure Container callbacks (ejbActivate, ejbPassivate, etc.).
So here are the rules:
==============================
The pure container callbacks--in other words, the methods that the client does not see and does not directly trigger, must NOT have any checked exceptions.
==============================
==============================
But all of the other business methods, including the ones whose names change inside the bean class (findByPrimaryKey() becomes ejbFindByPrimaryKey(), etc.) CAN have checked exceptions, and in the SPECIAL case of ejbCreate methods for CMP entity beans, MUST have CreateException declared in the bean code.
(This is the error in the book--we say that CreateException is optional, when in fact it is NOT optional for a CMP entity bean. For Session and BMP entity beans, CreateException IS optional.
==============================
Does that help?
If not, Roger will come to the rescue again!
cheers,
Kathy