I am creating an entity bean class using Eclipse, and it is providing the methods inherited from EntityBean with "throws EJBException, RemoteException". Do we need to be throwing EJBException and RemoteException from each of the EntityBean inherited methods (such as ejbActivate(), etc.) ? Do we need to throw these exceptions from each of the remotely exposed methods (getLastName(), etc.), or any other methods we add to a CMP entity bean class ? The reason I ask is because the Head First book doesn't show these exceptions in the sample codes for entity beans (for example p.318). I assume that the EJBException is omitted since it is a runtime exception, but I'm confused about the RemoteException - isn't RemoteException only needed by remote component and home interface methods ? Thanks in advance for any feedback.
James, You are correct about EJBException. There are notes about this in the Javadoc for EntityBean. For each of these methods there is a notation about the throws clause. The RemoteException is needed only for EJB 1.0 compatibility. It must NOT be thrown in EJB 2.0. You can of course narrow the throws clause and simply not include RemoteException in the method's throws clauses for your EJB. Eclipse has know way to know about this (what's stated in the note) and thinks you should by default declare it.
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Howdy -- Ken gave the perfect answer, so I'm just agreeing here. NO EJB 2.0 bean should declare RemoteException, ever from within the bean implementation methods. The only place in which you declare RemoteException is in a remote component or home interface. That's it, since EJB 1.1. But you are still *allowed* to in order to be compatible with EJB 1.0 requirements. EJBException is unchecked, so it's there only as a convenience, but you do not need to declare it. You don't have to declare exceptions on your business methods unless you really will/can throw them, and only if they are checked exceptions. So in that respect, your business methods adhere to normal Java exception rules. Of course there are other exception-handling rules for things like create methods, etc.... but that's different. cheers, Kathy "just coming back to life again" Sierra Thanks for all those who've been so patient and helpful while I've been away! I'll be getting back to you through email very soon. (Oh yeah, be glad you're taking the EJB exam and not the new SCWCD! It makes the SCBCD look like a walk in the park. I'm not kidding; the new SCWCD will be *really* hard. Too hard, in my opinion, although the beta test will determine that for sure. If too many questions are too difficult, they will be thrown out during beta.)