The basic model

This framework integrates tightly with hibernate. The scope of this documentation is not to describe how hibernate is working. We assume that you are already familiar with hibernate.

Directory structure for the model

The following describes the general directory structure when working with the model:

model
 -- the POJO
 +-- dao
    -- the DAO interface
     +-- jdbc
        -- the concrete hibernate implementation
        -- the hibernate mapping file

Let us use an entity called User as example and the base package is called org.jzonic.test. The following will show the files that are included:

src/org/jzonic/test/model/User.java
src/org/jzonic/test/model/dao/UserDAO.java
src/org/jzonic/test/model/dao/jdbc/HibernateUserDAO.java
src/org/jzonic/test/model/dao/jdbc/User.hbm.xml

The interface is necessary to decouple the application from the concrete hibernate implementation and to support using mock objects for unit testing.

You can use the CodeGenerator to build all these files automatically and do reverse engineering from an existing table. This will greatly simplify the development process.

Using the model

Every DAO is automatically added to the ApplicationContext upon startup. This means that every DAO is directly accessible with the getBean method like:

UserDAO userDAO = (UserDAO)ApplicationContext.getBean(UserDAO.class);

Note that the DAOs are referenced by their interface here.

The AbstractController also implements a getBean to easily access any DAO. In your controller code you can do something like:

public void login() {
  if ( isPostRequest() ) {
    UserDAO userDAO = (UserDAO)getBean(UserDAO.class);
    .....
   }
}

There is even an easier way describe later.

Page: BasicModel last edited by admin on 03/19/2009 21:22 revision: 2
Labels:  (none)    Permalink