java.sql.SQLException: Field ‘ID’ doesn’t have a default value

ID should be auto-increment. If you forget it, this will be the problem ūüôā

24HY_RAJAHMUNDRY_2418927g

17:04:49,830         WARN JDBCExceptionReporter:77 - SQL Error: 1364, SQLState: HY000
17:04:49,832        ERROR JDBCExceptionReporter:78 - Field 'ID' doesn't have a default value
17:04:49,843        ERROR AuthorizationInterceptor:88 - Error while invoking request
org.hibernate.exception.GenericJDBCException: could not insert: [com.eginnovations.mypo.entity.Category]
.....
Caused by: java.sql.SQLException: Field 'ID' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)

autoincrement

Advertisements

Spring 4 MVC + Spring 3 Security + Hibernate 4 – integration with java annotations

Dear folks,

This may be the final post in the Spring 4 environment setup. We have already completed 3 out of 4 stages.

Last but not least, we do the hibernate integration in this post. Since ibatis is not doing good, Hibernate is monopolize the ORM market. Hence hibernate will be used in our next project. Here comes the integration. This tutorial assumes you have completed all the above steps and have the web project ready now.

hibernate.properties

Save this property file to the class path. I usually save at /src folder

jdbc.driverClassName = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://localhost:3306/vriksha
jdbc.username = root
jdbc.password =
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = true
hibernate.format_sql = true

Changes to WebMvcConfigurerAdapter

We are doing important changes to the MVC Configurer. Please check all the methods and beans except getViewResolver(), which exists from the beginning.

package org.grassfield.conf;

import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "org.grassfield.conf", "org.grassfield.common.dao", "org.grassfield.common.entity" })
@EnableTransactionManagement
@PropertySource(value={"classpath:hibernate.properties"})
public class ApplicationContextConfig extends WebMvcConfigurerAdapter {
    
    @Autowired
    private Environment environment;

    @Bean(name = "viewResolver")
    public InternalResourceViewResolver getViewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

    @Bean(name = "datasource")
    public static DataSource dataSource() {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://localhost:3306/license_prod_2");
        ds.setUsername("root");
        ds.setPassword("");

        return ds;
    }
    
    @Bean
    public LocalSessionFactoryBean sessionFactory(){
        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
        sessionFactory.setDataSource(dataSource());
        sessionFactory.setPackagesToScan(new String[]{"org.grassfield.common.entity"});
        sessionFactory.setHibernateProperties(hibernateProperties());
        return sessionFactory;
        
    }
    
    private Properties hibernateProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
        properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
        properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
        return properties;        
    }
    
    @Bean
    @Autowired
    public HibernateTransactionManager transactionManager(SessionFactory sessionFactory){
        HibernateTransactionManager tx = new HibernateTransactionManager();
        tx.setSessionFactory(sessionFactory);
        return tx;
    }
}

 

Changes to HomeController

HomeController exists from the beginning. We are changing the method which handles the /protect url. This is secured by Spring Security. Please note the DAO call and ModelAndView population. Wiring Controller with a DAO is a bad practice. Don’t do it in your project, dear coders!

@RequestMapping("/protect")
    public ModelAndView handleProtectedRequest(HttpServletRequest arg0,
            HttpServletResponse arg1) throws Exception {
        List<UserRole> userRoleList = this.userRoleDAO.list();
        System.out.println(userRoleList);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("protect");
        modelAndView.addObject("userRoleList", userRoleList);
        return modelAndView;
    }

 

New DAO tier

We will be getting a list of user roles. Following is the interface for UserRoleDAO.

package org.grassfield.common.dao;

import java.util.List;

import org.grassfield.common.entity.UserRole;

public interface IUserRoleDAO {
    public List<UserRole> list();
}

 

The implementation goes like this. Please note the annotations.

package org.grassfield.common.dao;

import java.util.List;

import org.grassfield.common.entity.UserRole;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class UserRoleDAO implements IUserRoleDAO {
    @Autowired
    private SessionFactory sessionFactory;
    
    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    @Transactional
    public List<UserRole> list() {
        Session currentSession = this.sessionFactory.getCurrentSession();
        @SuppressWarnings("unchecked")
        List<UserRole> list = currentSession.createQuery("From UserRole").list();
        return list;
    }
}

Entity/Model

And finally, our entity class is given below. Please note the annotations.

/*
 * Package: com.eginnovations.common.entity 
 * FileName: UserRole.java
 * (c) 2010 eG Innovations private limited
 * 
 * Created by pandian on May 27, 2010 3:15:36 PM
 */
package org.grassfield.common.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * The Class UserRole.
 */
@Entity
@Table(name="user_role")
public class UserRole {
    @Id @GeneratedValue
    @Column(name="id")
    private Long id;
    
    @Column(name="NAME")
    private String name;
    
    @Column(name="EMAIL_PERMISSION")
    private String emailPermission;
    
    /**
     * Gets the id.
     * 
     * @return the id
     */
    public Long getId() {
        return id;
    }
    
    /**
     * Sets the id.
     * 
     * @param id the new id
     */
    public void setId(Long id) {
        this.id = id;
    }
......
.....

 

Now load the protected URL! You will see the list of the user roles.

spring4_hibernate4

Okay, This is more or less ready now. I need to do some refactoring. We can start building it by next weekend. Till then Bye!

spring-tool-suite-project-logo java8-logo image00110 Apache-Tomcat-logo

 

 

Could not obtain transaction-synchronized Session for current thread

I autowire a DAO with the controller. Do not ask me, ‘Hey stupid, why do you want to couple the controller with a DAO’. Because I’m setting up the environment. Service tier is not yet ready. Ok!

package org.grassfield.vriksha.controller;

import java.util.List;

import org.grassfield.common.dao.IUserRoleDAO;
import org.grassfield.common.entity.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class VrikshaController {
    @Autowired
    IUserRoleDAO userRoleDAO;
    
    
    public IUserRoleDAO getUserRoleDAO() {
        return userRoleDAO;
    }


    public void setUserRoleDAO(IUserRoleDAO userRoleDAO) {
        this.userRoleDAO = userRoleDAO;
    }


    @RequestMapping("/welcome")
    public ModelAndView helloWorld(){
        System.out.println("1");
        List<UserRole> list = this.userRoleDAO.list();
        String message = "<h3>Welcome</h3>"+list;
        return new ModelAndView("welcome", "message", message);
    }
}

Okay, While hitting the page, it is very eager to show me an error page. Could not obtain transaction-synchronized Session for current thread

 
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
    org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)
    org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
    org.grassfield.common.dao.UserRoleDAO.list(UserRoleDAO.java:26)

It is my mistake on the configuration XML. Let’s add the annotation-driven tag.

    <tx:annotation-driven/>
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

It is not sufficient.

bean schema locations.

<beans xmlns=”http://www.springframework.org/schema/beans&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns:p=”http://www.springframework.org/schema/p&#8221;
xmlns:context=”http://www.springframework.org/schema/context&#8221;
xmlns:tx=”http://www.springframework.org/schema/tx&#8221;
xsi:schemaLocation=”http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd”&gt;

Here you go! This will help you to resolve this error.

 

ROO – 2: Creating a simple application: Simple User Record

If you have not checked earlier my post on “ROO for rapid spring development“, please do it.

Here we will create another application, which will create the entity Logins with two fields username and password.

Project Setup

roo> project --topLevelPackage org.grassfield.userapp
Created ROOT/pom.xml
Created SRC_MAIN_RESOURCES
Created SRC_MAIN_RESOURCES/log4j.properties
Created SPRING_CONFIG_ROOT
Created SPRING_CONFIG_ROOT/applicationContext.xml

Database Setup

roo> jpa setup --provider HIBERNATE --database MYSQL Created SPRING_CONFIG_ROOT/database.properties Please update your database details in src/main/resources/META-INF/spring/database.properties. Updated SPRING_CONFIG_ROOT/applicationContext.xml Created SRC_MAIN_RESOURCES/META-INF/persistence.xml Updated ROOT/pom.xml [added dependencies mysql:mysql-connector-java:5.1.18, org.hibernate:hibernate-core:3.6.9.Final, org.hibernate:hibernate-entitymanager:3.6.9.Final, org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final, org.hibernate:hibernate-validator:4.2.0.Final, javax.validation:validation-api:1.0.0.GA, cglib:cglib-nodep:2.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.6, commons-dbcp:commons-dbcp:1.3]

Edit the database.properties and add the mysql database name, username, password.

Ensure you have created the database on MySQL, and the user has access to the database.

Entity Setup

roo> entity jpa --class ~.User --testAutomatically
 Reserved SQL keyword 'User' is not permitted as simple type name
 ~.User roo> entity jpa --class ~.Login --testAutomatically
 Created SRC_MAIN_JAVA/org/grassfield/userapp
 Created SRC_MAIN_JAVA/org/grassfield/userapp/Login.java
 Created SRC_TEST_JAVA/org/grassfield/userapp
 Created SRC_TEST_JAVA/org/grassfield/userapp/LoginDataOnDemand.java
 Created SRC_TEST_JAVA/org/grassfield/userapp/LoginIntegrationTest.java
 Created SRC_MAIN_JAVA/org/grassfield/userapp/Login_Roo_Configurable.aj
 Created SRC_MAIN_JAVA/org/grassfield/userapp/Login_Roo_Jpa_Entity.aj
 Created SRC_MAIN_JAVA/org/grassfield/userapp/Login_Roo_Jpa_ActiveRecord.aj
 Created SRC_MAIN_JAVA/org/grassfield/userapp/Login_Roo_ToString.aj
 Created SRC_TEST_JAVA/org/grassfield/userapp/LoginIntegrationTest_Roo_Configurable.aj
 Created SRC_TEST_JAVA/org/grassfield/userapp/LoginDataOnDemand_Roo_DataOnDemand.aj
 Created SRC_TEST_JAVA/org/grassfield/userapp/LoginIntegrationTest_Roo_IntegrationTest.aj
 Created SRC_TEST_JAVA/org/grassfield/userapp/LoginDataOnDemand_Roo_Configurable.aj

Add Fields to Entity

~.Login roo> field string --fieldName username --notNull
 Updated SRC_MAIN_JAVA/org/grassfield/userapp/Login.java
 Updated SRC_TEST_JAVA/org/grassfield/userapp/LoginDataOnDemand_Roo_DataOnDemand.aj
 Created SRC_MAIN_JAVA/org/grassfield/userapp/Login_Roo_JavaBean.aj
~.Login roo> field string --fieldName password --notNull
 Updated SRC_MAIN_JAVA/org/grassfield/userapp/Login.java
 Updated SRC_TEST_JAVA/org/grassfield/userapp/LoginDataOnDemand_Roo_DataOnDemand.aj
 Updated SRC_MAIN_JAVA/org/grassfield/userapp/Login_Roo_JavaBean.aj

Setup Spring MVC

~.Login roo> web mvc setup
 Created ROOT/src/main/webapp/WEB-INF/spring
 Created ROOT/src/main/webapp/WEB-INF/spring/webmvc-config.xml
 Created ROOT/src/main/webapp/WEB-INF/web.xml
 Updated ROOT/src/main/webapp/WEB-INF/spring/webmvc-config.xml
 Created ROOT/src/main/webapp/images
 Created ROOT/src/main/webapp/images/add.png
 Created ROOT/src/main/webapp/images/banner-graphic.png
 Created ROOT/src/main/webapp/images/create.png
 Created ROOT/src/main/webapp/images/delete.png
 Created ROOT/src/main/webapp/images/favicon.ico
 Created ROOT/src/main/webapp/images/list.png
 Created ROOT/src/main/webapp/images/resultset_first.png
 Created ROOT/src/main/webapp/images/resultset_last.png
 Created ROOT/src/main/webapp/images/resultset_next.png
 Created ROOT/src/main/webapp/images/resultset_previous.png
 Created ROOT/src/main/webapp/images/show.png
 Created ROOT/src/main/webapp/images/springsource-logo.png
 Created ROOT/src/main/webapp/images/update.png
 Created ROOT/src/main/webapp/styles
 Created ROOT/src/main/webapp/styles/alt.css
 Created ROOT/src/main/webapp/styles/standard.css
 Created ROOT/src/main/webapp/WEB-INF/classes
 Created ROOT/src/main/webapp/WEB-INF/classes/alt.properties
 Created ROOT/src/main/webapp/WEB-INF/classes/standard.properties
 Created ROOT/src/main/webapp/WEB-INF/layouts
 Created ROOT/src/main/webapp/WEB-INF/layouts/default.jspx
 Created ROOT/src/main/webapp/WEB-INF/layouts/layouts.xml
 Created ROOT/src/main/webapp/WEB-INF/views
 Created ROOT/src/main/webapp/WEB-INF/views/header.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/menu.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/footer.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/views.xml
 Created ROOT/src/main/webapp/WEB-INF/views/dataAccessFailure.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/index-template.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/index.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/resourceNotFound.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/uncaughtException.jspx
 Created ROOT/src/main/webapp/WEB-INF/tags/form
 Created ROOT/src/main/webapp/WEB-INF/tags/form/create.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/dependency.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/find.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/list.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/show.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/update.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/checkbox.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/column.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/datetime.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/display.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/editor.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/input.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/reference.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/select.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/simple.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/table.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/textarea.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/menu
 Created ROOT/src/main/webapp/WEB-INF/tags/menu/category.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/menu/item.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/menu/menu.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util
 Created ROOT/src/main/webapp/WEB-INF/tags/util/language.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/load-scripts.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/pagination.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/panel.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/placeholder.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/theme.tagx
 Created ROOT/src/main/webapp/WEB-INF/i18n
 Created ROOT/src/main/webapp/WEB-INF/i18n/messages.properties
 Created ROOT/src/main/webapp/images/en.png
 Updated ROOT/src/main/webapp/WEB-INF/i18n/application.properties
 Updated ROOT/src/main/webapp/WEB-INF/web.xml
 Updated ROOT/pom.xml [added dependencies org.springframework:spring-webmvc:${spring.version}, org.springframework.webflow:spring-js-resources:2.2.1.RELEASE, commons-digester:commons-digester:2.1, commons-fileupload:commons-fileupload:1.2.2, javax.servlet.jsp.jstl:jstl-api:1.2, org.glassfish.web:jstl-impl:1.2, javax.el:el-api:1.0, joda-time:joda-time:1.6, javax.servlet.jsp:jsp-api:2.1, commons-codec:commons-codec:1.5; updated project type to war; added dependency org.apache.tiles:tiles-jsp:2.2.2]
 Updated SRC_MAIN_WEBAPP/WEB-INF/views/footer.jspx
~.Login roo> web mvc all --package ~.web
 Created SRC_MAIN_JAVA/org/grassfield/userapp/web
 Created SRC_MAIN_JAVA/org/grassfield/userapp/web/LoginController.java
 Updated SRC_MAIN_WEBAPP/WEB-INF/spring/webmvc-config.xml
 Created SRC_MAIN_JAVA/org/grassfield/userapp/web/ApplicationConversionServiceFactoryBean.java
 Created SRC_MAIN_WEBAPP/WEB-INF/views/logins
 Created SRC_MAIN_WEBAPP/WEB-INF/views/logins/views.xml
 Updated SRC_MAIN_WEBAPP/WEB-INF/views/logins/views.xml
 Updated SRC_MAIN_WEBAPP/WEB-INF/i18n/application.properties
 Created SRC_MAIN_JAVA/org/grassfield/userapp/web/ApplicationConversionServiceFactoryBean_Roo_ConversionService.aj
 Created SRC_MAIN_JAVA/org/grassfield/userapp/web/LoginController_Roo_Controller.aj
 Created SRC_MAIN_WEBAPP/WEB-INF/views/logins/list.jspx
 Created SRC_MAIN_WEBAPP/WEB-INF/views/logins/show.jspx
 Created SRC_MAIN_WEBAPP/WEB-INF/views/logins/create.jspx
 Updated SRC_MAIN_WEBAPP/WEB-INF/views/menu.jspx
 Created SRC_MAIN_WEBAPP/WEB-INF/views/logins/update.jspx

Run the Selenium tests

~.web roo> selenium test --controller ~.web.LoginController
Updated SRC_MAIN_WEBAPP/WEB-INF/i18n/application.properties
 Created SRC_MAIN_WEBAPP/selenium
 Created SRC_MAIN_WEBAPP/selenium/test-login.xhtml
 Created SRC_MAIN_WEBAPP/selenium/test-suite.xhtml
 Updated SRC_MAIN_WEBAPP/WEB-INF/views/menu.jspx
 Updated ROOT/pom.xml [added plugin org.codehaus.mojo:selenium-maven-plugin:2.1]
~.web roo> perform tests
 [INFO] Scanning for projects...
 [INFO]
 [INFO] ------------------------------------------------------------------------
 [INFO] Building userapp 0.1.0.BUILD-SNAPSHOT
 [INFO] ------------------------------------------------------------------------
 [INFO] oo>
 [INFO] --- aspectj-maven-plugin:1.2:compile (default) @ userapp ---
 [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] oo>
 [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ userapp ---
 [debug] execute contextualize
 [INFO] Using 'UTF-8' encoding to copy filtered resources.
 [INFO] Copying 4 resources
 [INFO] oo>
 [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ userapp ---
 [INFO] Nothing to compile - all classes are up to date
 [INFO] oo>
 [INFO] --- aspectj-maven-plugin:1.2:test-compile (default) @ userapp ---
 [WARNING] advice defined in org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect 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]
 [WARNING] advice defined in org.springframework.scheduling.aspectj.AbstractAsyncExecutionAspect has not been applied [Xlint:adviceDidNotMatch]
 [INFO] oo>
 [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ userapp ---
 [debug] execute contextualize
 [INFO] Using 'UTF-8' encoding to copy filtered resources.
 [INFO] skip non existing resourceDirectory /home/pandian/apps/userapp/src/test/resources
 [INFO] oo>
 [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ userapp ---
 [INFO] Nothing to compile - all classes are up to date
 [INFO] oo>
 [INFO] --- maven-surefire-plugin:2.9:test (default-test) @ userapp ---
 [INFO] Surefire report directory: /home/pandian/apps/userapp/target/surefire-reports
 ~.web roo>
 -------------------------------------------------------
 T E S T S
 -------------------------------------------------------
 ~.web roo>
 Results :>
 ~.web roo>
 Tests run: 9, Failures: 0, Errors: 0, Skipped: 0
 ~.web roo>
 [INFO] ------------------------------------------------------------------------
 [INFO] BUILD SUCCESS
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time: 6.317s
 [INFO] Finished at: Sun May 27 16:29:56 IST 2012
 [INFO] Final Memory: 9M/215M
 [INFO] ------------------------------------------------------------------------

Bundling

~.web roo> perform package
 [INFO] Scanning for projects...
 [INFO]
 [INFO] ------------------------------------------------------------------------
 [INFO] Building userapp 0.1.0.BUILD-SNAPSHOT
 [INFO] ------------------------------------------------------------------------
 [INFO] oo>
 [INFO] --- aspectj-maven-plugin:1.2:compile (default) @ userapp ---
 [INFO] oo>
 [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ userapp ---
 [debug] execute contextualize
 [INFO] Using 'UTF-8' encoding to copy filtered resources.
 [INFO] Copying 4 resources
 [INFO] oo>
 [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ userapp ---
 [INFO] Nothing to compile - all classes are up to date
 [INFO] oo>
 [INFO] --- aspectj-maven-plugin:1.2:test-compile (default) @ userapp ---
 [INFO] oo>
 [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ userapp ---
 [debug] execute contextualize
 [INFO] Using 'UTF-8' encoding to copy filtered resources.
 [INFO] skip non existing resourceDirectory /home/pandian/apps/userapp/src/test/resources
 [INFO] oo>
 [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ userapp ---
 [INFO] Nothing to compile - all classes are up to date
 [INFO] oo>
 [INFO] --- maven-surefire-plugin:2.9:test (default-test) @ userapp ---
 [INFO] Tests are skipped.
 [INFO] oo>
 [INFO] --- maven-war-plugin:2.1.1:war (default-war) @ userapp ---
 [INFO] Packaging webapp
 [INFO] Assembling webapp [userapp] in [/home/pandian/apps/userapp/target/userapp-0.1.0.BUILD-SNAPSHOT]
 [INFO] Processing war project
 [INFO] Copying webapp resources [/home/pandian/apps/userapp/src/main/webapp]
 [INFO] Webapp assembled in [158 msecs]
 [INFO] Building war: /home/pandian/apps/userapp/target/userapp-0.1.0.BUILD-SNAPSHOT.war
 [INFO] WEB-INF/web.xml already added, skipping
 [INFO] ------------------------------------------------------------------------
 [INFO] BUILD SUCCESS
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time: 3.314s
 [INFO] Finished at: Sun May 27 16:35:44 IST 2012
 [INFO] Final Memory: 8M/150M
 [INFO] ------------------------------------------------------------------------

Create Eclipse project

~.web roo> perform eclipse
 [INFO] Scanning for projects...
 [INFO]
 [INFO] ------------------------------------------------------------------------
 [INFO] Building userapp 0.1.0.BUILD-SNAPSHOT
 [INFO] ------------------------------------------------------------------------
 [INFO] oo>
 [INFO] --- maven-eclipse-plugin:2.7:clean (default-cli) @ userapp ---
 [INFO] Deleting file: .project
 [INFO] Deleting file: .classpath
 [INFO] Deleting file: .wtpmodules
 [INFO] Deleting file: .component
 [INFO] Deleting file: org.eclipse.wst.common.component
 [INFO] Deleting file: org.eclipse.wst.common.project.facet.core.xml
 [INFO] Deleting file: org.eclipse.jdt.core.prefs
 [INFO] Deleting file: org.eclipse.ajdt.ui.prefs
 [INFO] oo>
 [INFO] >>> maven-eclipse-plugin:2.7:eclipse (default-cli) @ userapp >>>
 [INFO] oo>
 [INFO] --- aspectj-maven-plugin:1.2:compile (default) @ userapp ---
 [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] oo>
 [INFO] <<< maven-eclipse-plugin:2.7:eclipse (default-cli) @ userapp <<< [INFO] oo>
 [INFO] --- maven-eclipse-plugin:2.7:eclipse (default-cli) @ userapp ---
 [INFO] Adding support for WTP version 2.0.
 [INFO] Using Eclipse Workspace: null
 [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
 [INFO] Wrote settings to /home/pandian/apps/userapp/.settings/org.eclipse.jdt.core.prefs
 [INFO] Wrote Eclipse project for "userapp" to /home/pandian/apps/userapp.
 [INFO] oo>
 Javadoc for some artifacts is not available.
 Please run the same goal with the -DdownloadJavadocs=true parameter in order to check remote repositories for javadoc.
 List of artifacts without a javadoc archive:
 o cglib:cglib-nodep:2.2.2
 o commons-codec:commons-codec:1.5
 o commons-dbcp:commons-dbcp:1.3
 o commons-pool:commons-pool:1.5.6
 o commons-digester:commons-digester:2.1
 o commons-beanutils:commons-beanutils:1.8.3
 o commons-fileupload:commons-fileupload:1.2.2
 o javax.el:el-api:1.0
 o javax.servlet:servlet-api:2.5
 o javax.servlet.jsp:jsp-api:2.1
 o javax.servlet.jsp.jstl:jstl-api:1.2
 o javax.transaction:jta:1.1
 o javax.validation:validation-api:1.0.0.GA
 o joda-time:joda-time:1.6
 o junit:junit:4.10
 o org.hamcrest:hamcrest-core:1.1
 o log4j:log4j:1.2.16
 o mysql:mysql-connector-java:5.1.18
 o net.sf.flexjson:flexjson:2.1
 o org.apache.commons:commons-lang3:3.1
 o org.apache.tiles:tiles-jsp:2.2.2
 o org.apache.tiles:tiles-servlet:2.2.2
 o org.apache.tiles:tiles-core:2.2.2
 o org.apache.tiles:tiles-api:2.2.2
 o org.slf4j:jcl-over-slf4j:1.6.4
 o org.slf4j:slf4j-api:1.6.4
 o org.apache.tiles:tiles-template:2.2.2
 o org.aspectj:aspectjrt:1.6.12
 o org.aspectj:aspectjweaver:1.6.12
 o org.glassfish.web:jstl-impl:1.2
 o org.hibernate:hibernate-core:3.6.9.Final
 o antlr:antlr:2.7.6
 o commons-collections:commons-collections:3.1
 o dom4j:dom4j:1.6.1
 o org.hibernate:hibernate-commons-annotations:3.2.0.Final
 o org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final
 o org.hibernate:hibernate-entitymanager:3.6.9.Final
 o javassist:javassist:3.12.0.GA
 o org.hibernate:hibernate-validator:4.2.0.Final
 o org.slf4j:slf4j-log4j12:1.6.4
 o org.springframework:spring-aop:3.1.0.RELEASE
 o aopalliance:aopalliance:1.0
 o org.springframework:spring-asm:3.1.0.RELEASE
 o org.springframework:spring-beans:3.1.0.RELEASE
 o org.springframework:spring-core:3.1.0.RELEASE
 o org.springframework:spring-aspects:3.1.0.RELEASE
 o org.springframework:spring-context:3.1.0.RELEASE
 o org.springframework:spring-expression:3.1.0.RELEASE
 o org.springframework:spring-context-support:3.1.0.RELEASE
 o org.springframework:spring-test:3.1.0.RELEASE
 o org.springframework:spring-jdbc:3.1.0.RELEASE
 o org.springframework:spring-tx:3.1.0.RELEASE
 o org.springframework:spring-orm:3.1.0.RELEASE
 o org.springframework:spring-webmvc:3.1.0.RELEASE
 o org.springframework:spring-web:3.1.0.RELEASE
 o org.springframework.roo:org.springframework.roo.annotations:1.2.1.RELEASE
 o commons-io:commons-io:2.1
 o org.springframework.webflow:spring-js-resources:2.2.1.RELEASE
 ~.web roo>
 [INFO] ------------------------------------------------------------------------
 [INFO] BUILD SUCCESS
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time: 3.696s
 [INFO] Finished at: Sun May 27 16:35:59 IST 2012
 [INFO] Final Memory: 12M/218M
 [INFO] ------------------------------------------------------------------------

Thats all!

~.web roo> quit

Web Preview

pandian@pandian-ubuntu:~/apps/userapp$ mvn tomcat:run
 [INFO] Scanning for projects...
 [INFO]
 [INFO] ------------------------------------------------------------------------
 [INFO] Building userapp 0.1.0.BUILD-SNAPSHOT
 [INFO] ------------------------------------------------------------------------
 [INFO]
 [INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) @ userapp >>>
 [INFO]
 [INFO] --- aspectj-maven-plugin:1.2:compile (default) @ userapp ---
 [INFO]
 [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ userapp ---
 [debug] execute contextualize
 [INFO] Using 'UTF-8' encoding to copy filtered resources.
 [INFO] Copying 4 resources
 [INFO]
 [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ userapp ---
 [INFO] Nothing to compile - all classes are up to date
 [INFO]
 [INFO] <<< tomcat-maven-plugin:1.1:run (default-cli) @ userapp <<<
 [INFO]
 [INFO] --- tomcat-maven-plugin:1.1:run (default-cli) @ userapp ---
 [INFO] Running war on http://localhost:8080/userapp
 [INFO] Creating Tomcat server configuration at /home/pandian/apps/userapp/target/tomcat
 May 27, 2012 4:36:26 PM org.apache.catalina.startup.Embedded start
 INFO: Starting tomcat server
 May 27, 2012 4:36:26 PM org.apache.catalina.core.StandardEngine start
 INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
 May 27, 2012 4:36:26 PM org.apache.catalina.core.ApplicationContext log
 INFO: Initializing Spring root WebApplicationContext
 May 27, 2012 4:36:28 PM org.apache.catalina.core.ApplicationContext log
 INFO: Initializing Spring FrameworkServlet 'userapp'
 May 27, 2012 4:36:28 PM org.apache.coyote.http11.Http11Protocol init
 INFO: Initializing Coyote HTTP/1.1 on http-8080
 May 27, 2012 4:36:28 PM org.apache.coyote.http11.Http11Protocol start
 INFO: Starting Coyote HTTP/1.1 on http-8080

Database

mysql> show tables;
 +-------------------+
 | Tables_in_userapp |
 +-------------------+
 | login |
 +-------------------+
 1 row in set (0.00 sec)
mysql> select * from login;
 +----+------------+------------+---------+
 | id | password | username | version |
 +----+------------+------------+---------+
 | 1 | pandian | pandian | 0 |
 | 2 | fieldgrass | grassfield | 0 |
 +----+------------+------------+---------+
 2 rows in set (0.00 sec)

 

Roo for rapid Spring development

Whenever we try to build a new project, we used to start from scratch with our favourite IDE. Spring is used for rapid development. In such case, initial setup of the project takes time. Everybody wants a template to begin with Spring. “Can I find a blank war for Struts?” is a frequently being asked question. Hence we introduce Roo from SpringTools

If you take any generic Spring development project, it contains the following environment setup activities. This is a recursive one for every project.

We can overcome this with Roo. It helps you to create and start a Spring Web in less than 10 minutes!

How to Use Roo?

Spring has some pre-requisites. You need to ensure JDK 1.6 is installed. You should have Maven and Roo. Download them and ensure it is in PATH. Usually I will create symlinks for the frequently used applications in /usr/bin. (This tutorial is created for Ubuntu or any Unix Platforms. I hope you are smart enough to not to ask me to write the same for Windows ūüôā )

$ sudo ln -s /home/pandian/Downloads/maven/apache-maven-3.0.4/bin/mvn /usr/bin/mvn

$ sudo ln -s /home/pandian/Downloads/spring-roo-1.2.1.RELEASE/bin/roo /usr/bin/roo

Now this is the time to execute Roo

$ roo
roo>hint

You should see something like the following!

The project has been created. But we need persistence support!

roo> project --topLevelPackage org.grassfield.roo
 Created ROOT/pom.xml
 Created SRC_MAIN_RESOURCES
 Created SRC_MAIN_RESOURCES/log4j.properties
 Created SPRING_CONFIG_ROOT
 Created SPRING_CONFIG_ROOT/applicationContext.xml

I like to use MySQL with Hibernate

roo> jpa setup --provider HIBERNATE --database MYSQL
Created SPRING_CONFIG_ROOT/database.properties
Please update your database details in src/main/resources/META-INF/spring/database.properties.
Updated SPRING_CONFIG_ROOT/applicationContext.xml
Created SRC_MAIN_RESOURCES/META-INF/persistence.xml
Updated ROOT/pom.xml [added dependencies mysql:mysql-connector-java:5.1.18, org.hibernate:hibernate-core:3.6.9.Final, org.hibernate:hibernate-entitymanager:3.6.9.Final, org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final, org.hibernate:hibernate-validator:4.2.0.Final, javax.validation:validation-api:1.0.0.GA, cglib:cglib-nodep:2.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.6, commons-dbcp:commons-dbcp:1.3]

I am not updating the DB information in the database.properties located in

/home/pandian/Downloads/spring-roo-1.2.1.RELEASE/bin/src/main/resources/META-INF/spring
$ cat database.properties
 #Updated at Sat Apr 28 11:47:56 IST 2012
 #Sat Apr 28 11:47:56 IST 2012
 database.driverClassName=com.mysql.jdbc.Driver
 database.url=jdbc\:mysql\://localhost\:3306
 database.username=root
 database.password=pandian

This is the time to setup the DB. Let create an entity Timer.

roo> entity jpa --class ~.Timer --testAutomatically
 Created SRC_MAIN_JAVA/org/grassfield/roo
 Created SRC_MAIN_JAVA/org/grassfield/roo/Timer.java
 Created SRC_TEST_JAVA/org/grassfield/roo
 Created SRC_TEST_JAVA/org/grassfield/roo/TimerDataOnDemand.java
 Created SRC_TEST_JAVA/org/grassfield/roo/TimerIntegrationTest.java
 Created SRC_MAIN_JAVA/org/grassfield/roo/Timer_Roo_Configurable.aj
 Created SRC_MAIN_JAVA/org/grassfield/roo/Timer_Roo_ToString.aj
 Created SRC_MAIN_JAVA/org/grassfield/roo/Timer_Roo_Jpa_Entity.aj
 Created SRC_MAIN_JAVA/org/grassfield/roo/Timer_Roo_Jpa_ActiveRecord.aj
 Created SRC_TEST_JAVA/org/grassfield/roo/TimerIntegrationTest_Roo_Configurable.aj
 Created SRC_TEST_JAVA/org/grassfield/roo/TimerDataOnDemand_Roo_DataOnDemand.aj
 Created SRC_TEST_JAVA/org/grassfield/roo/TimerIntegrationTest_Roo_IntegrationTest.aj
 Created SRC_TEST_JAVA/org/grassfield/roo/TimerDataOnDemand_Roo_Configurable.aj
 ~.Timer

Lets create a field to the Timer entity now

roo> field string --fieldName message --notNull
 Updated SRC_MAIN_JAVA/org/grassfield/roo/Timer.java
 Updated SRC_TEST_JAVA/org/grassfield/roo/TimerDataOnDemand_Roo_DataOnDemand.aj
 Created SRC_MAIN_JAVA/org/grassfield/roo/Timer_Roo_JavaBean.aj
 ~.Timer

Lets build the web project now with spring MVC

roo> hint web mvc

It will be useful to execute the hint command after every execution.

~.Timer roo> web mvc setup
 Created ROOT/src/main/webapp/WEB-INF/spring
 Created ROOT/src/main/webapp/WEB-INF/spring/webmvc-config.xml
 Created ROOT/src/main/webapp/WEB-INF/web.xml
 Updated ROOT/src/main/webapp/WEB-INF/spring/webmvc-config.xml
 Created ROOT/src/main/webapp/images
 Created ROOT/src/main/webapp/images/add.png
 Created ROOT/src/main/webapp/images/banner-graphic.png
 Created ROOT/src/main/webapp/images/create.png
 Created ROOT/src/main/webapp/images/delete.png
 Created ROOT/src/main/webapp/images/favicon.ico
 Created ROOT/src/main/webapp/images/list.png
 Created ROOT/src/main/webapp/images/resultset_first.png
 Created ROOT/src/main/webapp/images/resultset_last.png
 Created ROOT/src/main/webapp/images/resultset_next.png
 Created ROOT/src/main/webapp/images/resultset_previous.png
 Created ROOT/src/main/webapp/images/show.png
 Created ROOT/src/main/webapp/images/springsource-logo.png
 Created ROOT/src/main/webapp/images/update.png
 Created ROOT/src/main/webapp/styles
 Created ROOT/src/main/webapp/styles/alt.css
 Created ROOT/src/main/webapp/styles/standard.css
 Created ROOT/src/main/webapp/WEB-INF/classes
 Created ROOT/src/main/webapp/WEB-INF/classes/alt.properties
 Created ROOT/src/main/webapp/WEB-INF/classes/standard.properties
 Created ROOT/src/main/webapp/WEB-INF/layouts
 Created ROOT/src/main/webapp/WEB-INF/layouts/default.jspx
 Created ROOT/src/main/webapp/WEB-INF/layouts/layouts.xml
 Created ROOT/src/main/webapp/WEB-INF/views
 Created ROOT/src/main/webapp/WEB-INF/views/header.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/menu.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/footer.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/views.xml
 Created ROOT/src/main/webapp/WEB-INF/views/dataAccessFailure.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/index-template.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/index.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/resourceNotFound.jspx
 Created ROOT/src/main/webapp/WEB-INF/views/uncaughtException.jspx
 Created ROOT/src/main/webapp/WEB-INF/tags/form
 Created ROOT/src/main/webapp/WEB-INF/tags/form/create.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/dependency.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/find.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/list.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/show.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/update.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/checkbox.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/column.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/datetime.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/display.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/editor.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/input.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/reference.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/select.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/simple.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/table.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/form/fields/textarea.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/menu
 Created ROOT/src/main/webapp/WEB-INF/tags/menu/category.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/menu/item.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/menu/menu.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util
 Created ROOT/src/main/webapp/WEB-INF/tags/util/language.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/load-scripts.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/pagination.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/panel.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/placeholder.tagx
 Created ROOT/src/main/webapp/WEB-INF/tags/util/theme.tagx
 Created ROOT/src/main/webapp/WEB-INF/i18n
 Created ROOT/src/main/webapp/WEB-INF/i18n/messages.properties
 Created ROOT/src/main/webapp/images/en.png
 Updated ROOT/src/main/webapp/WEB-INF/i18n/application.properties
 Updated ROOT/src/main/webapp/WEB-INF/web.xml
 Updated ROOT/pom.xml [added dependencies org.springframework:spring-webmvc:${spring.version}, org.springframework.webflow:spring-js-resources:2.2.1.RELEASE, commons-digester:commons-digester:2.1, commons-fileupload:commons-fileupload:1.2.2, javax.servlet.jsp.jstl:jstl-api:1.2, org.glassfish.web:jstl-impl:1.2, javax.el:el-api:1.0, joda-time:joda-time:1.6, javax.servlet.jsp:jsp-api:2.1, commons-codec:commons-codec:1.5; updated project type to war; added dependency org.apache.tiles:tiles-jsp:2.2.2]
 Updated SRC_MAIN_WEBAPP/WEB-INF/views/footer.jspx

and next….

roo> web mvc all --package ~.web
 Created SRC_MAIN_JAVA/org/grassfield/roo/web
 Created SRC_MAIN_JAVA/org/grassfield/roo/web/TimerController.java
 Updated SRC_MAIN_WEBAPP/WEB-INF/spring/webmvc-config.xml
 Created SRC_MAIN_JAVA/org/grassfield/roo/web/ApplicationConversionServiceFactoryBean.java
 Created SRC_MAIN_WEBAPP/WEB-INF/views/timers
 Created SRC_MAIN_WEBAPP/WEB-INF/views/timers/views.xml
 Updated SRC_MAIN_WEBAPP/WEB-INF/views/timers/views.xml
 Updated SRC_MAIN_WEBAPP/WEB-INF/i18n/application.properties
 Created SRC_MAIN_JAVA/org/grassfield/roo/web/TimerController_Roo_Controller.aj
 Created SRC_MAIN_WEBAPP/WEB-INF/views/timers/list.jspx
 Created SRC_MAIN_WEBAPP/WEB-INF/views/timers/show.jspx
 Created SRC_MAIN_WEBAPP/WEB-INF/views/timers/create.jspx
 Updated SRC_MAIN_WEBAPP/WEB-INF/views/menu.jspx
 Created SRC_MAIN_WEBAPP/WEB-INF/views/timers/update.jspx
 Created SRC_MAIN_JAVA/org/grassfield/roo/web/ApplicationConversionServiceFactoryBean_Roo_ConversionService.aj

Lets configure the tests!

roo> selenium test --controller ~.web.TimerController
 Updated SRC_MAIN_WEBAPP/WEB-INF/i18n/application.properties
 Created SRC_MAIN_WEBAPP/selenium
 Created SRC_MAIN_WEBAPP/selenium/test-timer.xhtml
 Created SRC_MAIN_WEBAPP/selenium/test-suite.xhtml
 Updated SRC_MAIN_WEBAPP/WEB-INF/views/menu.jspx
 Updated ROOT/pom.xml [added plugin org.codehaus.mojo:selenium-maven-plugin:2.1]
~.Timer

Lets run the tests now

~.web roo> perform tests
[INFO] ------------------------------------------------------------------------
 [INFO] BUILD FAILURE
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time: 3.818s
 [INFO] Finished at: Sat Apr 28 12:40:43 IST 2012
 [INFO] Final Memory: 7M/151M
 [INFO] ------------------------------------------------------------------------
 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.9:test (default-test) on project roo: There are test failures.
 [ERROR] o>
 [ERROR] Please refer to /home/pandian/Downloads/spring-roo-1.2.1.RELEASE/bin/newproj/target/surefire-reports for the individual test results.
 [ERROR] -> [Help 1]
 [ERROR] o>
 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
 [ERROR] o>
 [ERROR] For more information about the errors and possible solutions, please read the following articles:
 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Unfortunate, lets see the test log

2012-04-28 12:40:42,920 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table timer (id bigint not null auto_increment, message varchar(255) not null, version integer, primary key (id)) ENGINE=InnoDB
2012-04-28 12:40:42,920 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - No database selected
2012-04-28 12:40:43,176 [main] ERROR org.hibernate.util.JDBCExceptionReporter - No database selected
2012-04-28 12:40:43,190 [main] ERROR org.hibernate.util.JDBCExceptionReporter - No database selected
2012-04-28 12:40:43,201 [main] ERROR org.hibernate.util.JDBCExceptionReporter - No database selected
2012-04-28 12:40:43,205 [main] ERROR org.hibernate.util.JDBCExceptionReporter - No database selected
2012-04-28 12:40:43,209 [main] ERROR org.hibernate.util.JDBCExceptionReporter - No database selected
2012-04-28 12:40:43,213 [main] ERROR org.hibernate.util.JDBCExceptionReporter - No database selected
2012-04-28 12:40:43,216 [main] ERROR org.hibernate.util.JDBCExceptionReporter - No database selected
2012-04-28 12:40:43,221 [main] ERROR org.hibernate.util.JDBCExceptionReporter - No database selected

We have forgot to give the database name in config files.

I am creating a new Database roodb

mysql> create database roodb;

Hence the db property file is changed as below

$ cat ./src/main/resources/META-INF/spring/database.properties
#Updated at Sat Apr 28 12:35:06 IST 2012
 #Sat Apr 28 12:35:06 IST 2012
 database.driverClassName=com.mysql.jdbc.Driver
 database.url=jdbc\:mysql\://localhost\:3306/roodb
 database.username=root
 database.password=pandian

Let’s run the test again!

~.web roo> perform test
[INFO] ------------------------------------------------------------------------
 [INFO] BUILD SUCCESS
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time: 4.520s
 [INFO] Finished at: Sat Apr 28 12:51:22 IST 2012
 [INFO] Final Memory: 7M/151M
 [INFO] ------------------------------------------------------------------------

Cheers!

lets package it now

~.web roo> perform package
[INFO] Webapp assembled in [177 msecs]
[INFO] Building war: /home/pandian/Downloads/spring-roo-1.2.1.RELEASE/bin/newproj/target/roo-0.1.0.BUILD-SNAPSHOT.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:00.264s
[INFO] Finished at: Sat Apr 28 12:56:13 IST 2012
[INFO] Final Memory: 8M/151M
[INFO] ------------------------------------------------------------------------

I prefer eclipse build

.web roo> perform eclipse
 [INFO] ------------------------------------------------------------------------
 [INFO] BUILD SUCCESS
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time: 8:21.388s
 [INFO] Finished at: Sat Apr 28 13:07:00 IST 2012
 [INFO] Final Memory: 13M/145M
 [INFO] ------------------------------------------------------------------------
~.web roo> quit
 $mvn tomcat:run

Cheers!

Lets see what happened at DB end.

mysql> show tables;
+-----------------+
| Tables_in_roodb |
+-----------------+
| timer           |
+-----------------+
1 row in set (0.00 sec)
mysql> desc timer;
+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| message | varchar(255) | NO   |     | NULL    |                |
| version | int(11)      | YES  |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> select * from timer;
Empty set (0.00 sec)

jEDP – a simple WAR file with Spring 3, Hibernate 3, Struts 2 integration

This is the first reply I got it from one of my ex-colleague

this is what i want anna

When a newbie starts to learn popular frameworks, it is very natural to integrate them for ease of use and better maintenance. Else, we can choose the best of what we want. They may not be in a position to learn Grails immediately, which starts separate learning curve for him/her. So I have released a SIMPLE war file under GPL today which consists of

  • Struts 2 – for view layer
  • Spring 3 – for Business Logic
  • Hibernate 3 – for Spring ORM

I am sure, it will reduce the time taken for integrating the solutions. I am damn sure it will work, because, I have developed an in-house CRM tool for my Organization by EXTENDing this!

jEDPHere is the project home page

https://sourceforge.net/projects/jedp

I prefer Kenai for better documentation and issue tracking. So, Documentations are placed in Kenai Wiki

http://kenai.com/projects/jedp

Good Luck