About Business Methods

See Also

A business method is a method inside an enterprise bean that performs some function and can be called from outside the bean. Business methods are written in the bean class and exposed through local or remote interfaces. If a business method is meant to be called by beans and clients that are running in the same JVM (on the same server), they are registered in the bean's local interface. If the method is meant to be called from a remote client, it is registered in the bean's remote interface.

A session bean's business methods typically define tasks that the bean performs for clients. They are not necessarily associated with data in a database.

In EJB 2.1 programming, an entity bean represents a persistent business object whose data is stored in a database. The bean adds behavior specific to that data. Therefore, an entity bean's business methods are typically accessor and mutator methods that enable you to read and update information in a database that represents a business concept. Entity bean business methods are almost always local methods, since remote clients should only access an entity bean through a facade session bean.

Business Methods in the IDE

In the IDE, you can generate business methods by opening the bean class in the Source Editor, right-clicking anywhere in the body of the class, and choosing Insert Code > Add Business Method. You can also just code a regular method and then click the IDE hint in the left margin and choose an interface from the popup menu.

When you create an EJB 2.1 enterprise bean (J2EE 1.4), the IDE creates a special BeanInterfaceBusiness interface in which it registers business methods. The bean interface extends the Business interface and the bean class implements both the bean interface and the RemoteBusiness interface.

The advantage of this approach is that it lets you separate the business logic from implementation logic, and that it lets you check at compile-time that your bean implements the given interfaces. If you want to register business methods directly in the bean's interfaces, delete the Business interface files. Then edit the bean interface to not extend the Business interface and edit the bean class to not implement the Business interface.

When working with EJB 3.0 or EJB 3.1 enterprise beans, there is no need for a separate Business interface because the enterprise beans are regular Java objects and therefore have only the remote and local interfaces.

See Also
Defining a Business Method
About Session Beans
About Entity Beans

Legal Notices