Announcement Announcement Module
Collapse
No announcement yet.
new persistent class within an existing project Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • new persistent class within an existing project

    hi all...

    i have an existing project and wanted to create a new persistent class with ROO. The class was created fine and was able to add all the fields. but, when running my tests, I'm getting this error:

    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeService': Injection of persistence methods failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:src/test/resources/data-access-config.xml]: Invocation
     of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: org.testco.sample.application.Address
            at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:324)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:998)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
            at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
            at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:42)
            at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:173)
            at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:197)
            ... 21 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory'
     defined in URL [file:src/test/resources/data-access-config.xml]: Invocation of init method failed; nested exception is
    org.hibernate.AnnotationException: No identifier specified for entity: org.testco.sample.application.Address
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
    this seems to be an annotation/hibernate exception complaining about the ID field. that's defined in Address_Roo_Entity.aj. Is there any other config I need to do before ROO can work within an existing app. As of right now, I just used the 'new persistent class jpa...' command and added the ROO annotation jar to my pom.xml.

    thanks

  • #2
    Would you mind posting your org.testco.sample.application.Address.java file. I suspect you've added an identifier field to it manually. You can do that, but if you do it is necessary to properly annotate it as an identifier field. In most cases you can skip adding identifier fields via the Roo shell and Roo will therefore add one automatically.

    Comment


    • #3
      hi Ben...

      sure, below is my Address.java file. I did add 2 constructors. One an empty, the other takes in an Employee object. Both are in bold. if need me to try an reproduce the steps, let me know.

      thanks


      Code:
      package org.testco.sample.application;
      
      import javax.persistence.Entity;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      
      import org.springframework.roo.addon.entity.RooEntity;
      import org.springframework.roo.addon.javabean.RooJavaBean;
      import org.springframework.roo.addon.tostring.RooToString;
      
      @Entity
      @RooEntity
      @RooJavaBean
      @RooToString
      public class Address {
      	
         public Address() {
      
          }
      	
          public Address(Employee employee) {
          	this.employee = employee;
          }
      
          private String streetName;
      
          private String postalCode;
      
          private String city;
      
          private String country;
      
          @ManyToOne
          @JoinColumn
          private State state;
      
          @ManyToOne
          @JoinColumn
          private Employee employee;
      }

      Comment


      • #4
        I'm having trouble reproducing this. I use the following script from an empty directory:

        Code:
        create project org.testco.sample.application
        install jpa -provider HIBERNATE -database HYPERSONIC_IN_MEMORY 
        new persistent class jpa -name State -testAutomatically   
        add field string stateName
        new persistent class jpa -name Employee -testAutomatically 
        add field string employeeName
        new persistent class jpa -name Address -testAutomatically 
        add field string streetName
        add field string postalCode
        add field string city      
        add field string country
        add field reference jpa -type ~.State -fieldName state
        add field reference jpa -type ~.Employee -fieldName employee
        I then edit the Address.java to contain your two constructors, and reload Roo. It does not update any files, which is correct behavior given you defined a no-arg constructor explicitly.

        I can then successfully run "mvn test". I am using Roo engineering build rev 66.

        I considered you might be adding a field called "id" to the State or Employee classes, but when I did this I encountered a different error and logged this as http://jira.springframework.org/browse/ROO-60. I am interested in trying to understand what steps are needed to reproduce this, as I'd like to sort it out for you.

        Comment


        • #5
          hi Ben...thanks for taking the time! My apologies, I should have explained my scenario better.

          I have numerous Spring applications (been using it for years) and I wanted to see how ROO can help support those applications. Those applications were NOT created with ROO nor had any interaction with ROO previously.

          So, using an existing Spring application, I deleted out an entity and tried using ROO to generate that entity. Maybe I need to add more config somewhere to support the aspects/ROO? I haven't changed any of the *Address* files that ROO created, nor added/changed any existing configuration within the existing app.

          I can zip up my project and explain my steps to reproduce if you think that'll help. Let me know how you'd like to proceed...

          thanks

          Comment


          • #6
            Is it a Maven-based project? If so, please feel free to send it to my personal email ben dot alex at springsource dot com and I will be happy to take a look.

            Comment


            • #7
              sorry, this is not a ROO problem. i didn't have the aspectj-maven-plugin in my pom file. if you remove the plugin, this error is easily reproduced...

              sorry for the confusion.

              Comment

              Working...
              X