Shekhar Gulati is a Java Consultant with over 5 years experience.He is currently working with Xebia India an Agile Software Development company.The postings on this site and on his blog are his own and do not necessarily represent opinion of his employer. His own blog is at http://whyjava.wordpress.com/ and you can follow him on twitter here. Shekhar has posted 25 posts at DZone. View Full User Profile

Playing with Spring Roo and Hades

02.03.2011
| 8449 views |
  • submit to reddit

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.
Published at DZone with permission of its author, Shekhar Gulati.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Justin Forder replied on Sat, 2011/02/05 - 9:40pm

You say "Spring Roo follows domain driven design 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 DDD approach."

Actually Roo's approach follows the Active Record pattern, and DDD requires Repositories (like DAOs) which are separate from the Entity classes.

Shekhar Gulati replied on Sun, 2011/02/06 - 1:37pm in response to: Justin Forder

Thanks for correcting me. I will update the post

Justin Forder replied on Mon, 2011/02/07 - 9:46pm in response to: Shekhar Gulati

Thank you for the article. I'm impressed by Roo, but haven't been happy with its use of the Active Record pattern. I'm pretty sure I voted for the JIRA issue about it (it was a while ago). I've seen Rod Johnson demonstrating Roo, and he acknowledged that this was a controversial design choice.

I shall follow the development of Hades with interest - given that Oliver Gierke, the manager of the Hades project, works for SpringSource I hope that it will become a standard option in Roo.

Axel Regnoult replied on Thu, 2011/05/05 - 9:52am

Hi,

 I was looking for a solution for a repository for  SPRING ROO + GAE...Does Hades is works on GAE (BigTable) ?

Tks

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.