While EJB 3.0 persistence gains a lot of attention we should not forget that EJB is more than persistence but also contains session beans and messaging driven beans. Mike Keith and Linda DeMichiel gave an excellent overview of the changes and improvements we can expect on these EJB’s. They explained that the driving force of EJB 3.0 is ‘ease-of-development’. While the current EJB’s are very powerfull they are also quite complex. Based upon Java metadata (annotations), dependency injection and on default, standard, usage we’ll get rid of the EBJ interfaces, the deployment descriptor and of the SessionContext in the code. This makes EJB’s much more like real POJO’s which results in cleaner, more comprehensible and better testable code.
For example:
import javax.ejb.Stateless.*;
/**
* A simple stateless session bean implementing the incrementValue() method of the
* CalculateEJB interface.
*/
@Stateless(name="CalculateEJB")
public class CalculateEJBBean implements CalculateEJB {
int value = 0;
public String incrementValue() {
value++;
return "value incremented by 1";
}
}
Other improvements are the Enhanced Lifecycle Methods and Call Back Listeners: Instead of implementing the unnecessary callback methods like ejbActivate, ejbPassivate etc. any method can be designated to receive notifications for life cycle events. Another addition are Interceptors that are designed to intercepts a business method invocation.
EJB 3.0 will be backwards compatible and will support incremental migration.
Although the production release will be ready only until JavaOne, many vendors are already offering EJB 3.0 implementations.
More info: