Thursday, November 1, 2012

Create GWT Project with Spring Roo and Mongo DB using STS – Part 2

Now I will go through the next step and show you how to create the Mongo DB entities. To read the FIRST PART click HERE, to see how to create the project using Spring Roo and STS.

After you create the project you should see something like this:

image

Using the keyword “hint” in the Roo Shell allows you to see what is the next step. This is really very easy step by step wizard way to work. In my case I will go for the following Roo Command:

mongo setup

which setups the project to use Mongo DB. Inside your Roo Shell you should see something like this:

image

After you create the project you may get some errors like this one:

Description    Resource    Path    Location    Type
Referenced file contains errors (http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd). For more information, right click on the message in the Problems View and select "Show Details..." applicationContext-mongo.xml /ofers/src/main/resources/META-INF/spring line 1 XML Problem


To fix this click on the project with right mouse button and then from Maven select Update Project, like this:


image


This now should update your project and download the needed libraries. After that the error message will disappear.


Next major step is to create the entities. For that reason I create very simple tables, which I will use as domains entities into my project. This is the example.


image


Just for info, the ID in my table is not something you have to create, the Mongo DB database creates this automatically for every entry in the table. Also what is important to know is the “Reference” means you have Many to One relationship and “Set” means One to Many.


To create the entities using Roo you have to type following lines using the Roo Shell:


For PersonType table:

entity mongo --class ~.domain.PersonType --testAutomatically
field string --fieldName type --sizeMin 128 --notNull



For Person table:

entity mongo --class ~.domain.Person --testAutomatically
field string --fieldName title --sizeMin 16 --notNull
field string --fieldName firstname --sizeMin 128 --notNull
field string --fieldName lastname --sizeMin 128 --notNull
field string --fieldName street --sizeMin 256 --notNull
field number --fieldName plz --type java.lang.Integer
field string --fieldName city --sizeMin 128 --notNull
field string --fieldName email --sizeMin 256 --notNull
field number --fieldName dataofbirth --type java.lang.Integer
field string --fieldName pwd --sizeMin 128 --notNull
field reference --fieldName type --type ~.domain.PersonType



For the layer support:


 

repository mongo --interface ~.repository.PersonTypeRepository --entity ~.domain.PersonType
repository mongo --interface ~.repository.PersonRepository --entity ~.domain.Person

service --interface ~.service.PersonTypeService --entity ~.domain.PersonType
service --interface ~.service.PersonService --entity ~.domain.Person



 


Now you have the Mongo DB entities and you can proceed with the next step (Part 3) of this tutorial, which I will post very soon and which will show how to setup the GWT project.

3 comments:

  1. Hi Lyudmil, does "the latest spring roo" supports gwt & mongodb integration easily? Thx.

    ReplyDelete
  2. I was looking after this as well but the answer at the moment is not really. You can create your MongoDb entities and you can add also the GWT specific project staff with Roo but after that you have to create your proxies manually.

    ReplyDelete
  3. Hi Lyudmil, it is nearly 1 year after we last discuss GWT&MongoDb integration... So , is it ready mongodb &GWT integration at Spring Roo? : )

    ReplyDelete