What is the difference between EJB, hibernate, spring and JSF?

user261002 picture user261002 · Nov 25, 2010 · Viewed 49.5k times · Source

I am very confused with different java frameworks. I want to create a java server project to offer some Restful web-service, but I really dont know which framework I should choose. What is the difference between JSF, EJB, Hibernate and Spring? Please help me understand them more.

Answer

Sean Patrick Floyd picture Sean Patrick Floyd · Nov 26, 2010

These are frameworks for different layers.

  • JSF is for the view (web) layer, it's a component oriented framework (every part of a page is a component, it has state) like Wicket or Tapestry, and unlike Action frameworks like Spring MVC, Struts or Stripes

    Books: Core JavaServer Faces (3rd Edition)
    Tutorials: CoreServlets.com

  • EJB 3.x is a container that's part of the JavaEE stack. It does things like dependency injection and bean lifecycle management. You usually need a full JavaEE application server for EJB3

    Tutorials: JavaEE 6 Tutorial: EJB
    Books: EJB 3 in Action

  • Spring is also a container, but Spring can run in any java code (a simple main class, an applet, a web app or a JavaEE enterprise app). Spring can do almost everything EJB can do and a lot more, but I'd say it's most famous for dependency injection and non-intrusive transaction management

    Online Reference (excellent)
    Books: I couldn't find a good english book on Spring 3.x, although several are in the making

  • Hibernate was the first big ORM (Object relational mapper) on the Java Platform, and as such has greatly inspired JPA (which is part of the EJB3 standard but can be used without an EJB container). I would suggest coding against JPA and only using hibernate as a provider, that way you can easily switch to EclipseLink etc.

    Books: Pro JPA 2: Mastering the Javaâ„¢ Persistence API (not hibernate-specific),
    Java Persistence with Hibernate (getting a bit old)