[ Team LiB ] |
D.3 Business Tier Antipatterns
MistakeEJBs are used when they provide few benefits, leading to an unnecessarily bloated or complex application. Watch for It WhenEJB features such as CMP, transactions, or security are not needed, few clients access the business tier, entity beans are simply a wrapper to an existing database, session beans are used as a gateway to other remote services, or business services do not need to be distributed. SolutionOften entity beans can be replaced with local commands or JavaBeans working in conjunction with DAOs. Direct database access, flat files, and JDO can also provide lighter-weight persistence mechanisms than entity EJBs. Session EJBs can often be replaced with business delegates or other, non-EJB façades.
MistakeFrequent calls to remote EJB getter and setter methods slow down the entire application and saturate the network. Watch for It WhenRemote entity EJBs are used directly, get or set methods of remote EJBs are called frequently, especially when iterating over a collection of EJBs (Figure D-1). Figure D-1. Round-trippingSolutionRefactor remote entity EJB calls to use a facade and a DTO. Use a session EJB as a façade to copy the entity EJBs into DTOs before they are sent across the network. Set values by sending back modified DTOs.
MistakeA stateful session EJB is used unnecessarily, causing much higher overhead for the EJB server. Watch for It WhenUsing any stateful session EJBs, arguments are passed into the create method of a session EJB to avoid passing the data later, or session EJBs are used specifically to store state, such as in a shopping cart. SolutionConvert stateful into stateless by passing all state with every call to the bean. If there are too many arguments, consider using a client-side adaptor to store them. Store other persistent data (even if it is not permanent) using entity EJBs. |
[ Team LiB ] |