Search This Blog


Sunday, June 19, 2011

JEE6: JSF + JPA - EJB = More Code

Without an EJB you will need for every EntityManager interaction at least 4 lines of code:
2.EntityManager interaction
4.consistent error handling + trx.rollback

The creation and management of an EntityManager is not even included. The code will look like this:

With a single EJB 3 you can eliminate all the bloat - the EntityManager will be properly managed and injected by the container.
The same code will look like:

You could even build a generic and reusable CRUD Service. The @Stateless session bean can be directly injected into the backing bean then:

There is no additional XML, libraries or additional frameworks needed. You can just jar everything in a WAR and you are done. the whole EJB 3 container in Glassfish v3 is < 1MB.