Spring Roo Plugin and reverse DB : allways NPE

Hi, I don’t understand what I’m doing wrong:

I’ve installed STS (Spring IDE) including Spring Roo, downloaded the Vaadin Spring Roo Plugin, followed all explainations from the pizza example.
I’ve successfully generated the Pizza example from scratch and tested it ! All is working great ! Super !

So, I would like to test automatic generation from existing DB. To achieve this, I create a new DB in postgresql with the following table (DDL):

CREATE TABLE personne (
        id INTEGER NOT NULL,
        valor INTEGER NOT NULL,
        vedette CHARACTER VARYING(255),
        nom CHARACTER VARYING(255),
        prenom CHARACTER VARYING(255),
        telephone1 CHARACTER VARYING(255),
        fax CHARACTER VARYING(255),
        courriel CHARACTER VARYING(255),
        commentaire CHARACTER VARYING(255),
        nom_epouse CHARACTER VARYING(255),
        telephone2 CHARACTER VARYING(255),
        adresse_adresse CHARACTER VARYING(255),
        adresse_codepostal CHARACTER VARYING(255),
        adresse_commune CHARACTER VARYING(255),
        adresse_localite CHARACTER VARYING(255),
        adresse_province CHARACTER VARYING(255),
        adresse_rue CHARACTER VARYING(255),
        adresse_numero CHARACTER VARYING(255),
        adresse_boite CHARACTER VARYING(255),
        adresse_pays CHARACTER VARYING(255),
        adresse_telephone1 CHARACTER VARYING(255),
        adresse_telephone2 CHARACTER VARYING(255),
        adresse_fax CHARACTER VARYING(255),
        adresse_email CHARACTER VARYING(255),
        numero_niss CHARACTER VARYING(255),
        birth_date TIMESTAMP(6) WITHOUT TIME ZONE,
        encadrant_fk INTEGER,
        coordinateur_daccueil_fk INTEGER,
        accueillante_fk INTEGER,
        view_perid CHARACTER VARYING(100),
        view_accid CHARACTER VARYING(100),
        PRIMARY KEY (id),
        CONSTRAINT 2200_23162_1_not_null CHECK (id IS NOT NULL),
        CONSTRAINT 2200_23162_2_not_null CHECK (valor IS NOT NULL)
    );

So, only one table in my DB.

I’ve created a new project (in STS: New, Spring Roo Project) with the following informations:
Project Name: atl
Base Package: be.one

I leave all the rest by default.

STS crete the project then open the Roo Console, so I Type the following commands:

project --topLevelPackage be.one.atl
persistence setup --provider HIBERNATE --database POSTGRES 

here, Roo ask to populate the “database.properties” file, so I fill it with my DB informations then test it with the command

database properties list

All is fine so I continue :

database introspect --schema public
database reverse engineer --schema public --package ~.database
controller all --package ~.web
perform tests

At this point, Spring Roo has generated my entities “Personne.java” so it can see my Database and access it.
I continue with the following command:

vaadin setup --applicationPackage ~.web --baseName Atlas --themeName theme1 --useJpaContainer false

Wonderfull, it create some others classes like:

AbstractEntityView.java
AbstractEntityView_Roo_AbstractEntityView.aj
AtlasApplication.java
AtlasEntityManagerView.java
AtlasEntityManagerView_Roo_VaadinEntityManagerView.aj
AtlasWindow.java
AutomaticEntityForm.java
EntityEditor.java
EntityFieldWrapper.java
EntitySetFieldWrapper.java
EntityTableColumnGenerator.java

It also created the “theme1” and adapted the web.xml. So the Vaadin Plugin work perfectly.
But now, the last command fail:

vaadin generate all --package ~.web.ui --visuallyComposable true

It stop with the following error:

NullPointerException at com.vaadin.spring.roo.addon.entityform.VisuallyComposableFormCreationHelper.<init>(VisuallyComposableFormCreationHelper.java:45)

What do I wrong ?

Following the full roo logs:
[i]

    ____  ____  ____  
   / __ \/ __ \/ __ \ 
  / /_/ / / / / / / / 
 / _, _/ /_/ / /_/ /  
/_/ |_|\____/\____/    1.1.1.RELEASE [rev 156ccd6]



Welcome to Spring Roo. For assistance press CTRL+SPACE or type "hint" then hit ENTER.
roo> [color=#FF0000]
persistence setup --provider HIBERNATE --database POSTGRES
[/color]
Updated ROOT\pom.xml [Removed redundant artifacts]

Updated SRC_MAIN_RESOURCES\META-INF\spring\applicationContext.xml
Created SRC_MAIN_RESOURCES\META-INF\persistence.xml
Created SRC_MAIN_RESOURCES\META-INF\spring\database.properties
Updated ROOT\pom.xml [Added dependencies postgresql:postgresql:8.4-701.jdbc3, org.hibernate:hibernate-core:3.6.0.Final, org.hibernate:hibernate-entitymanager:3.6.0.Final, org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final, org.hibernate:hibernate-validator:4.1.0.Final, javax.validation:validation-api:1.0.0.GA, cglib:cglib-nodep:2.2, javax.transaction:jta:1.1, org.springframework:spring-jdbc:${spring.version}, org.springframework:spring-orm:${spring.version}, commons-pool:commons-pool:1.5.4, commons-dbcp:commons-dbcp:1.3]

Updated ROOT\pom.xml [Added repository https://repository.jboss.org/nexus/content/repositories/releases]

Please enter your database details in src/main/resources/META-INF/spring/database.properties.
roo> [color=#FF0000]
database properties list
[/color]
database.driverClassName = org.postgresql.Driver
database.password = stef
database.url = jdbc:postgresql://localhost:5432/one-atl-saga2
database.username = postgres
roo> [color=#FF0000]
database introspect --schema public
[/color]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.--><!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_3.dtd">

<database name="public">
    <table name="personne">
        <column name="id" primaryKey="true" required="true" size="10" type="4,int4"/>
        <column name="valor" primaryKey="false" required="true" size="10" type="4,int4"/>
        <column name="vedette" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="nom" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="prenom" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="telephone1" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="fax" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="courriel" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="commentaire" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="nom_epouse" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="telephone2" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_adresse" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_codepostal" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_commune" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_localite" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_province" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_rue" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_numero" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_boite" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_pays" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_telephone1" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_telephone2" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_fax" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="adresse_email" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="numero_niss" primaryKey="false" required="false" size="255" type="12,varchar"/>
        <column name="birth_date" primaryKey="false" required="false" size="29,6" type="93,timestamp"/>
        <column name="encadrant_fk" primaryKey="false" required="false" size="10" type="4,int4"/>
        <column name="coordinateur_daccueil_fk" primaryKey="false" required="false" size="10" type="4,int4"/>
        <column name="accueillante_fk" primaryKey="false" required="false" size="10" type="4,int4"/>
        <column name="view_perid" primaryKey="false" required="false" size="100" type="12,varchar"/>
        <column name="view_accid" primaryKey="false" required="false" size="100" type="12,varchar"/>
        <unique name="personne_pkey">
            <unique-column name="id"/>
        </unique>
        <unique name="pk__personne__7feafd3e">
            <unique-column name="id"/>
        </unique>
    </table>
</database>

roo> [color=#FF0000]
database reverse engineer --schema public --package ~.database
[/color]
Created SRC_MAIN_JAVA\be\one\database
Created SRC_MAIN_JAVA\be\one\database\Personne.java
Updated SRC_MAIN_RESOURCES\META-INF\persistence.xml
Created ROOT\.roo-dbre
Created SRC_MAIN_JAVA\be\one\database\Personne_Roo_ToString.aj
Created SRC_MAIN_JAVA\be\one\database\Personne_Roo_Configurable.aj
Created SRC_MAIN_JAVA\be\one\database\Personne_Roo_DbManaged.aj
Created SRC_MAIN_JAVA\be\one\database\Personne_Roo_Entity.aj
roo> [color=#FF0000]
controller all --package ~.web
[/color]
be.one.web roo> [color=#FF0000]
perform tests
[/color]
[INFO]
 Scanning for projects...
[INFO]
                                                                         
[INFO]
 ------------------------------------------------------------------------
[INFO]
 Building atl2 0.1.0.BUILD-SNAPSHOT
[INFO]
 ------------------------------------------------------------------------
[INFO]
 
[INFO]
 --- aspectj-maven-plugin:1.0:compile (default) @ atl2 ---
[WARNING]
 advice defined in org.springframework.scheduling.aspectj.AbstractAsyncExecutionAspect has not been applied [Xlint:adviceDidNotMatch]

[WARNING]
 advice defined in org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl has not been applied [Xlint:adviceDidNotMatch]

[WARNING]
 advice defined in org.springframework.mock.staticmock.AbstractMethodMockingControl has not been applied [Xlint:adviceDidNotMatch]

[INFO]
 
[INFO]
 --- maven-resources-plugin:2.4.2:resources (default-resources) @ atl2 ---
[INFO]
 Using 'UTF-8' encoding to copy filtered resources.
[INFO]
 Copying 4 resources
[INFO]
 
[INFO]
 --- maven-compiler-plugin:2.1:compile (default-compile) @ atl2 ---
[INFO]
 Nothing to compile - all classes are up to date
[INFO]
 
[INFO]
 --- aspectj-maven-plugin:1.0:test-compile (default) @ atl2 ---
[INFO]
 
[INFO]
 --- maven-resources-plugin:2.4.2:testResources (default-testResources) @ atl2 ---
[INFO]
 Using 'UTF-8' encoding to copy filtered resources.
[INFO]
 Copying 0 resource
[INFO]
 
[INFO]
 --- maven-compiler-plugin:2.1:testCompile (default-testCompile) @ atl2 ---
[INFO]
 Nothing to compile - all classes are up to date
[INFO]
 
[INFO]
 --- maven-surefire-plugin:2.5:test (default-test) @ atl2 ---
[INFO]
 Surefire report directory: C:\Datas\_Coder\Prj_Vaadin\atl2\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO]
 ------------------------------------------------------------------------
[INFO]
 BUILD SUCCESS
[INFO]
 ------------------------------------------------------------------------
[INFO]
 Total time: 14.969s
[INFO]
 Finished at: Sat Feb 05 16:29:42 CET 2011
[INFO]
 Final Memory: 5M/15M
[INFO]
 ------------------------------------------------------------------------
be.one.web roo> [color=#FF0000]
vaadin setup --applicationPackage ~.web --baseName Atlas --themeName theme1 --useJpaContainer false
[/color]
Performing vaadin setup
Updated ROOT\pom.xml [Added dependency com.vaadin:vaadin:6.5.0.pre2]

Updated ROOT\pom.xml [Added dependency com.vaadin:com.vaadin.spring.roo.annotations:0.9.1.BUILD-SNAPSHOT]

Updated ROOT\pom.xml [Added dependency org.vaadin.addons:customfield:0.8.0]

Updated ROOT\pom.xml [Added dependency org.springframework:spring-web:${spring.version}]

Updated ROOT\pom.xml [Added repository vaadin-snapshots]

Updated ROOT\pom.xml [Added repository vaadin-addons]

Updated ROOT\pom.xml [Added dependency com.vaadin.addon:beanvalidation-addon:0.6.1]

Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\styles.css
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\img
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\img\menu-item-separator.png
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\img\new-button.png
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\img\menu-item-sel-bg.png
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\img\sidebar-bg.png
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\img\edit-icon.png
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\entityviews
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\entityviews\entityviews.css
Created SRC_MAIN_WEBAPP\VAADIN\themes\theme1\entityviews\entitymanagerview.css
Created SRC_MAIN_WEBAPP\WEB-INF
Created SRC_MAIN_WEBAPP\WEB-INF\web.xml
Updated SRC_MAIN_WEBAPP\WEB-INF\web.xml
Updated ROOT\pom.xml [Updated project type to war]

Created SRC_MAIN_JAVA\be\one\web
Created SRC_MAIN_JAVA\be\one\web\AtlasApplication.java
Created SRC_MAIN_JAVA\be\one\web\AtlasWindow.java
Created SRC_MAIN_JAVA\be\one\web\AtlasEntityManagerView.java
Created SRC_MAIN_JAVA\be\one\web\AbstractEntityView.java
Created SRC_MAIN_JAVA\be\one\web\AutomaticEntityForm.java
Created SRC_MAIN_JAVA\be\one\web\EntityFieldWrapper.java
Created SRC_MAIN_JAVA\be\one\web\EntitySetFieldWrapper.java
Created SRC_MAIN_JAVA\be\one\web\EntityTableColumnGenerator.java
Created SRC_MAIN_JAVA\be\one\web\EntityEditor.java
Created SRC_MAIN_JAVA\be\one\web\AtlasEntityManagerView_Roo_VaadinEntityManagerView.aj
Created SRC_MAIN_JAVA\be\one\web\AbstractEntityView_Roo_AbstractEntityView.aj
be.one.web roo> [color=#FF0000]
vaadin generate all --package ~.web.ui --visuallyComposable true
[/color]
Created SRC_MAIN_JAVA\be\one\web\ui
Created SRC_MAIN_JAVA\be\one\web\ui\PersonneView.java
Undo create SRC_MAIN_JAVA\be\one\web\ui\PersonneView.java
Undo create SRC_MAIN_JAVA\be\one\web\ui
[color=#FF0000]
NullPointerException at com.vaadin.spring.roo.addon.entityform.VisuallyComposableFormCreationHelper.<init>(VisuallyComposableFormCreationHelper.java:45)
[/color]
be.one.web roo> 

[/i]

Any idea ?
Thank’s
SteF

The Vaadin view generation did not handle well the case where the entity did not have a version field/accessor. This could happen when reverse engineering a database.

I hope the latest build will help: https://oss.sonatype.org/content/repositories/vaadin-snapshots/com/vaadin/com.vaadin.spring.roo.addon/0.9.1.BUILD-SNAPSHOT/com.vaadin.spring.roo.addon-0.9.1.BUILD-20110206.115708-9.jar . It also has other fixes and some new features that were not in the version linked from the wiki page in case you were using it.

Thank’s a lot for your response, unfortunately, it doesn’t help totally:
The last package still doesn’t work.

But, after renaming the field which act as version field (was “valor” and now renamed to “version”) all seems to generate correctly.

So, it implies that I should modify all the tables of my database: approximately 220 tables … ouch !

Thank’s anyway,

SteF.

What happens with the latest version? NPE or something else?

I’m not at my development environment at the moment and I haven’t used DBRE, but it seems Roo DBRE add-on does not give you the option to configure the field to use as the version field by hand. If you rather touch the Java files for entities than the database tables, you could try to see if you get this done by adding the versionField=… annotation parameter for
@RooEntity
.

This is exactly the same error as before.

Your’e right, I should change the database version field name or change the annotation after Spring Roo generate all his files because in our application, many tables have the version field called “valor” !

This application was generated by a consultant company which used AndroMDA. They created only the UML file with the uses cases and AndroMDA generate all the application.
As it is a big application, many developpers have worked on the UMLs, and some of them use “version” as version field name and some others use “valor” … :frowning:

This AndroMDA tools generate tons of garbage code, by example, for 300 different screens, it generate 2000 JSP, 3000 action classes for struts, and the Struts-config file was about 27.000 lines !!!
Totally unmaintainable !

I can’t recreate all from scratch, because the services are very complexes with many business rules, so I would like to only refactor de presentation side: Struts, JSP, ActionBeans, ActionForms, Validation, …
This implies I should find a quick way to recreate all the forms for the CRUD operations.
And this is where comes Vaadin …

The only way I find to create CRUD Form from Vaadin is to use Spring Roo with the Vaadin Plugin and reverse the database.
After generation, I only have to keep generated Vaadin Forms and put it in place of all the garbage code generated by AndroMDA, then link the Vaadin Forms with the old services.

This will avoid me the painly work of redisign all by myself !
I don’t have choice, because this project should be in production in 08/2011 (I’m scare !)

Do you know another way to speed up Form generation with Vaadin ?

Best regards,
SteF.

What you are up against is quite a challenge, and in my opinion compromises will certainly be required to have any chance to make that deadline. You will have to think carefully about priorities with respect to development time, quality, maintainability, usability and UI look etc. - and probably take some risks.

Some background work will be required to share as much of the UI code between the displays as possible. This includes things like field generation, display of certain properties, validation etc. on the UI side as well as how to connect the UI to the back-end logic. Using annotations in entities for things like validation sounds like a very good idea. You will probably not have much time to fine tune every form or display, so try to make the shared parts good enough to cover your needs, evolving them together with your code. Be prepared to prototype - and to throw away quick prototypes and unsuccessful attempts.

While the Vaadin add-on for Spring Roo might eventually be good for this, I would be careful about using it in a large production application at this point. It has several limitations and bugs, makes some assumptions (even beyond what Roo itself makes), and the generated code is not as efficient as it should be. Also, while partly encapsulated, the entity fetch and update logic is built around JPA, and some changes might be required to make it interface with other kinds of services.

Future versions probably will change the structure of the generated code a little, at least in some classes.

The good point about Roo is that you can remove it - from specific classes or from the whole project. However, you do lose a lot of automatic updates when doing so, and parts of the generated code are designed around rebuilding the aspects automatically rather than moving some pieces of logic to superclasses. Therefore, to modify certain behaviors, you would either need to modify the code generation by the Vaadin Roo add-on or bypass those parts of what Roo generates - easy on the method level, but a bit harder to generalize to apply to all your entity views etc. Removing the use of Roo would certainly reduce the maintainability of your application, at least unless you then do some refactoring in the affected classes.

Feedback on the Roo add-on is of course welcome - I would like to see it evolve to be usable even in some larger production applications, but I don’t think Roo itself is quite there yet, and the Vaadin add-on even less so. Do try it out, though - I believe there are good ideas in what it does and you can probably borrow both code and ideas even if you don’t use it directly. You could even create a first
prototype
of the application with it.