Seam without EJB3

When I tell people that you can now run Seam apps outside of the EJB3 container, I got two typical responses: "You must be joking" or "This is not news. We have been running Seam in Tomcat from day one".

Well, both responses have their points. Seam is developed and marketed as a "framework for Java EE 5.0", and to "support the EJB3 component model in the web tier". It has always been tied closely with EJB3. It is true that Seam applications have always been able to deploy to Tomcat with the help of JBoss Embeddable EJB3. But the keyword here is "Embeddable EJB3" -- the application bootstraps its own EJB3 container. With Seam 1.1, you can finally deploy Seam application in plain J2EE server or in Tomcat without embedded EJB3 runtime!

Seam has always supported POJO components in addition to EJB3 components. You can use Seam POJOs to replace EJB3 session beans and Hibernate POJOs to replace EJB3 entity beans. Instead of writing

JAVA:
  1. @Stateful
  2. @Name(myBizComp)
  3. public class ManagerAction implements Manager {
  4.   @PersistenceContext (type=EXTENDED)
  5.   private EntityManager em;
  6.  
  7.   ... ...
  8.  
  9.   @Destroy @Remove
  10.   public void destroy () { }
  11. }

You can simply write

JAVA:
  1. @Name(myBizComp)
  2. public class ManagerPOJO {
  3.   @In (create=true)
  4.   private Session session;
  5.  
  6.   ... ...
  7. }

However, in the past, even if your application is entirely written in Seam POJOs, you still need EJB3 container to run it. With Seam 1.1, we finally get rid of this dependency. As a result, you can deploy Seam applications in any J2EE app servers (JBoss, WebLogic, WebSphere, Oracle etc.) as well as Tomcat (without the need to bootstrap an EJB3 container). For JBoss customers, that also means you can get official support for your Seam applications now (the EJB3 stuff is not supported until JBoss AS 5).

Of course, there is no free lunch. Running Seam POJOs outside of EJB3 container means that you do not get container services such as async mesaging, deployment management etc. But the Seam runtime does provide injection of the managed EntityManager (or Hibernate Session) object as well as transaction demarcation. So, for basic database driven web applications, you will proably do just fine.

Anyway, I am writing a white paper on this subject as we speak and it will be adequately covered in the book. But for the impatient, checkout the "jpa" and "hibernate" example apps in the Seam 1.1 distribution. They both run out of the EJB3 container -- the "jpa" example uses the Hibernate JPA persistence provider (same as EJB3 session beans) and the "hibernate" example simply uses Hibernate POJOs.

Update: Checkout the Seam POJO app articles here.

6 Responses to “Seam without EJB3”

  1. David G. Says:

    It would be very interesting a post on how to migrate a JBoss Seam 1.0.1 app to 1.1.

    See u :)

  2. kent Says:

    So are there any benefits of using session beans over the entityHome and entityQuery objects?

  3. Quelques outils pour développer une application open source: Une application open source basée sur JEE 5 et JBoss Seam: Nuxeo5 « Le blog de Patrick Vergain Says:

    [...] - http://www.michaelyuan.com/blog/2006/11/14/seam-without-ejb3/ (”Seam has always supported POJO components in addition to EJB3 components. You can use Seam POJOs to replace EJB3 session beans and Hibernate POJOs to replace EJB3 entity beans“) [...]

  4. miguel_e Says:

    hi, one question, can i use EJB3 session beans and Hibernate POJOs in my application???? or a have to use Seam POJOs and Hibernate POJOs

    adeus
    miguel_e

  5. kampery Says:

    So are there any benefits of using session beans over the entityHome and entityQuery objects?

  6. Cyb Says:

    So are there any benefits of using session beans over the entityHome and entityQuery objects?

Leave a Reply