Michigan web site - 58 Chapter 3 The create() method throws
Saturday, November 10th, 200758 Chapter 3 The create() method throws two exceptions: java.rmi.RemoteException and javax.ejb.CreateException. Remote exceptions are necessary side effects of RMI-IIOP because the home object is a networked RMI-IIOP remote object. CreateException is also required in all create() methods. We explain this further in the Exceptions and EJB sidebar. Our home interface extends javax.ejb.EJBHome. This is required for all home interfaces. EJBHome defines a way to destroy an EJB object, so we don t need to write that method signature. EXCEPTIONS AND EJB Every networked object in EJB conforms to the RMI-IIOP standard and must throw a remote exception. Thus, every method in an EJB object and home object (such as our hello() method) must throw a remote exception. When such an exception is thrown, it indicates a special error condition a network failure, machine failure, or other catastrophic failure. But how can your beans throw exceptions that indicate regular, run-of-the- mill problems, such as bad parameters passed to a business method? EJB comes with some built-in exceptions to handle this, and it also allows you to define your own exception types. More formally, EJB defines the following exception types: . A system-level exception is a serious error that involves some critical failure, such as a database malfunction. . An application-level exception is a more routine exception, such as an indication of bad parameters to a method or a warning of an insufficient bank account balance to make a withdrawal. For example, in our Hello, World! home interface, we throw the standard exception javax.ejb.CreateException from the home interface s create() method. This is an ex- ample of a required application-level exception, indicating that some ordinary problem occurred during bean initialization. Why must we separate the concepts of system-level and application-level exceptions? The chief reason is that system-level exceptions are handled quite differently from application-level exceptions. For example, system-level exceptions are not necessarily thrown back to the client. Remember that EJB objects the container-generated wrappers for beans are middlemen between a bean s client and the bean itself. EJB objects have the ability to intercept any exceptions that beans may throw. This allows EJB objects to pick and choose which exceptions the client should see. In some cases, if a bean fails, it may be possible to salvage the client s invocation and redirect it to another bean. This is known as transparent fail-over, a quality of service that some EJB container/server vendors provide. This is an easy service to provide for stateless beans because there is no lost state when a bean crashes. Some high-end EJB products even provide transparent fail-over for
Are you a Mac user in a search of Mac web hosting provider? We are. once upon a time, we were just like you, trying to find somebody who knows. Unfortunately, we had no luck, so we decided to help many others like you, and us. our team developed Mac friendly web hosting plans, feature packed, constantly monitored, and more than affordable. With us, you are home. Sign up.