Announcement Announcement Module
Collapse
No announcement yet.
DBRE problem with entityManagerFactory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DBRE problem with entityManagerFactory

    I have an existing MySql Database.

    Here is my Roo Shell, I manually edited database.properties before doing the dbre.

    As you can see below, it looks very promising, it created all the entities and aspects as expected. I then did web mvc and that too looked good.

    Code:
        ____  ____  ____  
       / __ \/ __ \/ __ \ 
      / /_/ / / / / / / / 
     / _, _/ /_/ / /_/ /  
    /_/ |_|\____/\____/    1.1.4.RELEASE [rev f787ce7]
    
    
    Welcome to Spring Roo. For assistance press CTRL+SPACE or type "hint" then hit ENTER.
    roo> persistence setup --database MYSQL --provider HIBERNATE 
    Created SRC_MAIN_RESOURCES\META-INF\spring\database.properties
    Please update your database details in src/main/resources/META-INF/spring/database.properties.
    Updated ROOT\pom.xml [added dependencies mysql:mysql-connector-java:5.1.13, org.hibernate:hibernate-core:3.6.3.Final, org.hibernate:hibernate-entitymanager:3.6.3.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; added repository https://repository.jboss.org/nexus/content/repositories/releases]
    Updated SRC_MAIN_RESOURCES\META-INF\spring\applicationContext.xml
    Created SRC_MAIN_RESOURCES\META-INF\persistence.xml
    roo> database reverse engineer --schema no-schema-required --package com.corenttech.care.model
    Created SRC_MAIN_RESOURCES\dbre.xml
    Updated ROOT\pom.xml
    Updated SRC_MAIN_RESOURCES\META-INF\persistence.xml
    Created SRC_MAIN_JAVA\com\corenttech\care\model
    Created SRC_MAIN_JAVA\com\corenttech\care\model\ActionProperties.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\Actions.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\Applications.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\Carerulesrepository.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\ContactUs.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\ContactUsMessage.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\Criteria.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\EventProperties.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\EventTypes.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\Events.java
    Created SRC_MAIN_JAVA\com\corenttech\care\model\ExecutionLog.java...some omitted for brevity.
    roo> web mvc setup 
    Created SRC_MAIN_WEBAPP\WEB-INF\spring
    Created SRC_MAIN_WEBAPP\WEB-INF\spring\webmvc-config.xml
    Created SRC_MAIN_WEBAPP\WEB-INF\web.xml
    Created SRC_MAIN_WEBAPP\images
    ...some omitted for brevity
    Updated SRC_MAIN_WEBAPP\WEB-INF\web.xml
    Updated ROOT\pom.xml [added dependencies org.springframework:spring-web:${spring.version}, org.springframework:spring-webmvc:${spring.version}, org.springframework.webflow:spring-js-resources:2.2.1.RELEASE, commons-digester:commons-digester:2.0, commons-fileupload:commons-fileupload:1.2.1, javax.servlet:jstl: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.4; updated project type to war; added dependencies org.apache.tiles:tiles-core:2.2.1, org.apache.tiles:tiles-jsp:2.2.1]
    Updated SRC_MAIN_WEBAPP\WEB-INF\spring\webmvc-config.xml
    Updated SRC_MAIN_WEBAPP\WEB-INF\views\footer.jspx
    roo> web mvc all --package ~.cac 
    Created SRC_MAIN_JAVA\com\corenttech\care\cac
    Created SRC_MAIN_JAVA\com\corenttech\care\cac\ExecutionLogController.java
    .omitted for brevity
    Created SRC_MAIN_WEBAPP\WEB-INF\views\eventtypeses
    Created SRC_MAIN_WEBAPP\WEB-INF\views\eventtypeses\views.xml
    Updated SRC_MAIN_WEBAPP\WEB-INF\views\eventtypeses\views.xml
    Updated SRC_MAIN_WEBAPP\WEB-INF\views\menu.jspx
    Updated SRC_MAIN_WEBAPP\WEB-INF\views\eventtypeses\views.xml
    ...omitted for brevity
    Updated SRC_MAIN_WEBAPP\WEB-INF\views\menu.jspx
    Updated SRC_MAIN_WEBAPP\WEB-INF\i18n\application.properties
    Updated SRC_MAIN_WEBAPP\WEB-INF\spring\webmvc-config.xml
    Created SRC_MAIN_JAVA\com\corenttech\care\cac\ApplicationConversionServiceFactoryBean_Roo_ConversionService.aj
    Created SRC_MAIN_JAVA\com\corenttech\care\cac\ActionPropertiesController_Roo_Controller.aj
    Created SRC_MAIN_WEBAPP\WEB-INF\views\actionpropertieses\list.jspx
    Created SRC_MAIN_WEBAPP\WEB-INF\views\actionpropertieses\show.jspx
    Created SRC_MAIN_WEBAPP\WEB-INF\views\actionpropertieses\create.jspx
    ...omitted for brevity
    Created SRC_MAIN_WEBAPP\WEB-INF\views\executionlogs\list.jspx
    Created SRC_MAIN_WEBAPP\WEB-INF\views\executionlogs\show.jspx
    Created SRC_MAIN_WEBAPP\WEB-INF\views\executionlogs\create.jspx
    Created SRC_MAIN_WEBAPP\WEB-INF\views\executionlogs\update.jspx
    com.corenttech.care.cac roo> logging setup --level TRACE 
    Updated SRC_MAIN_RESOURCES\log4j.properties
    But trying to Run as on server gave me a 404 and the console showed a bunch of exceptions...starting with:

    Code:
    2011-05-26 06:23:15,085 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [C:\Users\user\Documents\workspace-sts-2.6.0.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\DBRETest\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [C:\Users\user\Documents\workspace-sts-2.6.0.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\DBRETest\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    I compared the sources and configuration files with a running application (as it happens the same one that created the database originally, also built with Roo) and couldn't find a difference. Any clues would be greatly appreciated.

  • #2
    DBRE problem additional information

    I tried a project clean and a maven clean and build.

    Now I am not getting the 404 but a 500 and the following exceptions...


    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'applicationConversionService' while setting constructor argument; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.corenttech.care.cac.ApplicationConversionServiceFactoryBean] for bean with name 'applicationConversionService' defined in ServletContext resource [/WEB-INF/spring/webmvc-config.xml]; nested exception is java.lang.ClassNotFoundException: com.corenttech.care.cac.ApplicationConversionServiceFactoryBean
    Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.corenttech.care.cac.ApplicationConversionServiceFactoryBean] for bean with name 'applicationConversionService' defined in ServletContext resource [/WEB-INF/spring/webmvc-config.xml]; nested exception is java.lang.ClassNotFoundException: com.corenttech.care.cac.ApplicationConversionServiceFactoryBean
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)

    Comment


    • #3
      Tale of Two Roos

      Hmmm,

      Thinking that I should create a simple single entity app with Roo on MySql, then use DBRE to see if I can recreate that app from the database created in the first app. Then I might be able to see the difference more easily.

      So I did that with this roo.log on the first app.


      Code:
      // Spring Roo 1.1.4.RELEASE [rev f787ce7] log opened at 2011-05-26 07:17:35
      project --topLevelPackage com.corenttech.dbre --projectName DBRETEST1 --java 6
      persistence setup --database MYSQL --provider HIBERNATE
      entity --class ~.model.Props 
      field string sectionTag
      field string propName
      field string propValue
      controller scaffold --class ~.web.PropsController --entity ~.model.Props
      logging setup --level TRACE
      That worked but I did notice the first time it threw a 404 but stopping cleaning working directory and restarting and redeploying had it running and able to save and list records....ok, so then I used DBRE on that same database as above.

      Code:
      // Spring Roo 1.1.4.RELEASE [rev f787ce7] log opened at 2011-05-26 07:32:17
      project --topLevelPackage com.corenttech.dbre.test2 --projectName DBRETest2 --java 6
      persistence setup --database MYSQL --provider HIBERNATE
      database reverse engineer --schema no-schema-required --package ~.model 
      controller scaffold --class ~.web.PropsController --entity ~.model.Props
      Ok, same deal on initial startup, so cleaned working directory stopped and restarted and redeployed. I expected to get either the couldn't find EntityManager or the Conversion class that I got earlier...this second one fired up, and able to save and list records....

      So, I looked inside and whoa, they two projects are greatly different. The DBRE generated version uses aspects much more than the first one. They both work, and I suspect the reasoning behind it is that a DBRE application should not be redefining Entities.

      I highly recommend this round trip of Roo as I learned a lot. I still don't know what the problem with my bigger DBRE project was, but I learned what it wasn't.

      First Props.java from DBRETest1 above.

      Code:
      package com.corenttech.dbre.model;
      
      import org.springframework.roo.addon.entity.RooEntity;
      import org.springframework.roo.addon.javabean.RooJavaBean;
      import org.springframework.roo.addon.tostring.RooToString;
      
      @RooJavaBean
      @RooToString
      @RooEntity
      public class Props {
      
          private String sectionTag;
      
          private String propName;
      
          private String propValue;
      }
      Props.java from DBRETest2

      Code:
      package com.corenttech.dbre.test2.model;
      
      import org.springframework.roo.addon.dbre.RooDbManaged;
      import org.springframework.roo.addon.entity.RooEntity;
      import org.springframework.roo.addon.javabean.RooJavaBean;
      import org.springframework.roo.addon.tostring.RooToString;
      
      @RooJavaBean
      @RooToString
      @RooEntity(table = "props")
      @RooDbManaged(automaticallyDelete = true)
      public class Props {
      }

      Comment


      • #4
        DBRE by design introduces all fields and accessor/mutators via the Db_Managed.aj ITD, as it needs to be able to add, modify and delete fields based on the DB schema. This is because we don't delete artifacts from the .java file as the user may have modified them, so what you are seeing in the two versions of Props is normal.

        Can you try with a standalone Roo shell without STS and see if the behaviour is any different?

        Comment


        • #5
          Originally posted by Alan Stewart View Post
          DBRE by design introduces all fields and accessor/mutators via the Db_Managed.aj ITD, as it needs to be able to add, modify and delete fields based on the DB schema. This is because we don't delete artifacts from the .java file as the user may have modified them, so what you are seeing in the two versions of Props is normal.

          Can you try with a standalone Roo shell without STS and see if the behaviour is any different?
          Ok, no problem understanding why my little test showed different results. But the test was intended to help solve the first problem the exceptions thrown after using DBRE on a bigger project. I had hoped to see those exceptions on a smaller scale to give me a better chance of figuring out why. Not getting the exceptions on the single table DBRE example, meant it was no help.

          Comment

          Working...
          X