Over a million developers have joined DZone.
Platinum Partner

Playing with Spring Roo and Hades

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

I have been using  Spring Roo for last 6 months but till today I had not used the Hades add-on for Roo. Finally today, I decided to play with the Hades add-on for Spring Roo. Spring Roo is a RAD tool for developing spring based applications using the popular and proven technologies and standards like maven, junit, JPA, JSR 330 bean validation etc. Hades is a utility library to work with Data Access Objects implemented with Spring and JPA. If you are newbie to Spring Roo and Hades you can refer to my posts on Roo and Hades. Spring Roo follows Active Record Pattern where in all the data access related methods(CRUD, finders etc. ) are defined in the entity class rather than defining them in a s a separate DAO layer. This is not liked by many Java developers as some developers prefer a layered approach more than Active Record approach. There is a very popular jira issue (ROO-301)related to providing an option to choose between different data access patterns. Hades Roo addon provides an option to create repositories for your entities. Lets create a sample Roo application using Hades addon.

  1. Create a directory called hades-roo
  2. Open a command line shell and go to the hades-roo director and start Roo Shell.
  3. Create a project using roo project command
    project --topLevelPackage com.shekhar.jl.hadesrooplay
  4. Setup persistence using persistence command
    persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
  5. Create a simple entity for which we want to create a hades repository
    entity --class ~.domain.MyUser
    field string --fieldName firstname --notNull
    field string --fieldName lastname --notNull
  6. Next we need to install hades addon . To do that type the following osgi commands
    osgi install --url http://hades.synyx.org/static/roo/repo/org/synyx/hades/org.synyx.hades.roo.addon/0.3.0.RELEASE/org.synyx.hades.roo.addon-0.3.0.RELEASE.jar
    osgi start --url http://hades.synyx.org/static/roo/repo/org/synyx/hades/org.synyx.hades.roo.addon/0.3.0.RELEASE/org.synyx.hades.roo.addon-0.3.0.RELEASE.jar
  7. Now if you type help command you will see two more commands. These commands are hades install and hades repository. The hades install command will add the hades maven dependency to the project and creates a spring context file specific to hades called applicationContext-hades.xml. This context file contains the hades:dao-config element which specifies the package in which repositories should be searched. This is similar to component scanning where all the classes annotated with @Component annotation are instantiated by the IOC container.
  8. Type hades install command which will install the Hades in your application.
    hades install
  9. Type hades repository command to create a new repository for an entity. You can use * if you want to create repositories for all entities.
    hades repository --entity *
With just two command we have set up Hades in our project. Spring Roo is a great tool which can help you get started on new technologies in minutes.

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}