I attended a NOVAJUG presentation on EJB3, Spring & Hibernate comparative analysis by Reza Rehman who is the co-author of EJB3 In Action by Manning publications . I have used EJB 2.1 in the past and now a heavy user of Spring technologies in all my current projects.
The presentation was really helpful and Reza showed a comparative analysis of EJB3, Spring & Hibernate technologies.
EJB3 embraces POJO (Plain Old Java Object) programming through annotation. In EJB3, the xml descriptor is made optional. The Object Relational mapping and object queries have been completely defined instead of being left up to the vendors to figure out.
EJB 3 makes heavy use of the so called "Intelligent Defaulting" whenever possible which is similar to convention over configuration concept used in Ruby on Rails.
Some of the comparative analysis shown by Reza are given below.
Use EJB3 if :
1. Your application uses annotations and dislike XML configuration.
2. Your application is stateful.
3. Standardization is an important consideration.
4. You use Java Server Faces and are considering using JBoss SEAM framework.
Use Spring if:
1. Your application requires fine grained control at the container level.
2. Your application requires a lot of configuration beyond gluing together components and resources.
3. Your application need to build non-standard but powerful solution stack like iBatis, Quartz or Spring Security.
4. Your application need advanced Aspect Oriented Programming features.
Use Hibernate if:
1. You like Hibernate API better than JPA.
2. You are unlikely to switch between persistence engines.
There is also another good article by Rod Coffin on Side-by-Side Comparison of Spring and EJB 3.0. The article is available at devx.com.