My book on EJB 3 is now on sale

I received an email from the editor informing me that the book is now printed and will be available in bookstores next week (from July 5th, 2010).

It is already available for sale on Amazon and ENI.

An online version is also available.

Here is the cover of the book :

SO3EJB_max

DAO design pattern in a session bean ?

I have recently been challenged by a colleague with a .Net background about the way I sometimes use session beans in web applications. Indeed, I like to implement DAOs as session beans.
Some people argue that it’s best not to directly implement CRUD methods in session beans.
The main reason being that they prefer to add another level of separation. For instance :

Session bean client
!
Session bean
!
business object helper class
!
DAO
!
ORM (Hibernate)
!
Database

A good example of this approach is the old implementation (EJB 2.0) of the The Java Pet Store by Sun. (API : http://java.sun.com/blueprints/code/jps131/src/).
My opinion is that this level of separation is not always necessary. And I believe using session beans as DAOs makes even more sense now that in EJB 3.x we have the Java Persistence API (entitymanager)  which already provides generic
database access methods (persist(), merge(), etc) :

Session bean client
!
Session bean DAO (JPA)
!
Entity bean
(JPA)
!
Database

Adam Bien explains it well in this post.

The difference between MVC 1 and MVC 2

The MVC architecture :
Model : Responsible for the business domain state knowledge
View : Responsible for a presentation view of the business domain
Controller : Responsible for controlling the flow and state of the user input

There are 2 models of the MVC architecture :
Model 1 (MVC 1) and Model 2 (MVC 2).

  • In MVC 1, the application control is decentralized, because the current page being displayed determines the next page to display.
  • In MVC 2, a controller servlet is the target of a request submission rather than the JSP pages themselves.
    A Model 2 architecture introduces a controller servlet between the browser and the JSP pages or servlet content being delivered.
    Struts is a good example of a framework based on MVC 2 because the ActionServlet servlet will select the proper view to respond to the user.
  • http://faq.javaranch.com/java/Model1Model2MVC
    http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html
    http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html

    Struts : MVC 2