EJB are wrapper around any kind of component, if you need data access, directory, resources, services, JMS, RMI, SOA etc. EJB Provides a standard way to wrap these thing under common umbrella which has many features. It can be compared to POJO but with lot of advance feature which you dont need write.
Reusing the code.
Scalability and reliability, Do pooling, limit connection and access easily, deploy on cluster environment.
Concurrency management, Easily configure concurrency using small annotation over methods such @Lock(READ), @Lock(WRITE).
Transaction handling, You don’t need to do any changes transaction is handled easily in EJB just annotate with @TransactionAttribute(modes), it covers JDBC, JPA, JCA and JMS easily.
Smart interaction, Easy transition with JPA, if entity is stateless it will create new transaction and isolate the JPA changes. In case of sharing Make is @Stateful and extend the scope by @PersistentContent(unitName=”AccountsPU, type=EXTENDED). So it caches the value from JPA and serve the same across multiple calls on same transaction.
Lifecycle hooks, it provides lifecycle hooks to inject code for initializing, destroying and cleaning activity.
Security based access, With simple annotation methods and classes can be secured. It provides user and roles access to methods in case they are required RBAC(Role based access control).
Standardization and portability
EJB sounds very nice starting from EJB 3.0, EJB 2.0 Entity bean has moved to separate Java EE specification JPA entities. EJB mainly had 3 type of bean.
Session bean - Contains business logic and have two type Stateful and stateless.
Message Driven Bean - It encapsulate onMessage methods and get invoked whenever there is a message received from queue or topic.
Entity Bean - It was used to persist the state of object but it has moved to JPA now. EJB 3.0 supports JPA it has removed the entity bean concept. It had two type CMP and BMP, CMP container provides many inbuilt function such persist, connect, transaction etc, while BMP programmer has to write that.