Spring Roo
  1. Spring Roo
  2. ROO-317

Support using an Abstract Entity base and providing version and id fields

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0.RC2
    • Fix Version/s: 1.0.0.RC3
    • Component/s: PERSISTENCE
    • Labels:
      None
    • Environment:
      windows/cygwin, Roo rev 359

      Description

      I created an abstract "base" entity with "id" and "version" fields. When I try to create new entity in Roo that extends this base entity, I get:

      Created SRC_MAIN_JAVA\com\abstracttest\domain\Person.java
      Undo create SRC_MAIN_JAVA\com\abstracttest\domain\Person.java
      User provided @javax.persistence.Id field but failed to provide a public 'getId()' method in 'com.abstracttest.domain.Person'
      roo>

      ...and Roo will not create the new entity.

      See forum for script and steps to reproduce.

        Activity

        Hide
        Ben Alex added a comment -

        There were a number of subtle errors in the EntityMetadata class, which have been corrected in SVN revision 369. The ITDs are now outputting correctly, provided that you follow the expected conventions:

        • "id" and "version" fields must not have a private access modifier (suggest making it package)
        • "id" and "version" fields should be correct annotated with the relevant JPA annotation
        • "id" and "version" fields should have accessors and mutators with a public access modifier

        If you do this, the intended model will work. Below is a sample script that illustrates correct behaviour and also the hand-edited abstract superclass.

        project --topLevelPackage com.abstracttest --projectName abstracttest
        
        persistence setup --provider OPENJPA --database HYPERSONIC_IN_MEMORY
        
        entity --name ~.domain.AbstractBaseEntity --abstract --mappedSuperclass
        field number id --type java.lang.Long
        field number version --type java.lang.Integer
        
        entity --name ~.domain.Person --extends ~.domain.AbstractBaseEntity
        field string --fieldName firstName --notNull
        test integration ~.domain.Person
        
        package com.abstracttest.domain;
        
        
        import javax.persistence.Entity;
        import org.springframework.roo.addon.javabean.RooJavaBean;
        import org.springframework.roo.addon.tostring.RooToString;
        import org.springframework.roo.addon.entity.RooEntity;
        import javax.persistence.MappedSuperclass;
        
        @Entity
        @RooJavaBean
        @RooToString
        @RooEntity
        @MappedSuperclass
        public abstract class AbstractBaseEntity {
        
            @javax.persistence.Id
            @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
            @javax.persistence.Column(name = "id")
            protected Long id;
        
            @javax.persistence.Version
            @javax.persistence.Column(name = "version")
            protected Integer version;
        
            public Long getId() { return id; }
            public void setId(Long id) { this.id = id; }
            public Integer getVersion() { return version; }
            public void setVersion(Integer version) { this.version = version; }
        }
        
        Show
        Ben Alex added a comment - There were a number of subtle errors in the EntityMetadata class, which have been corrected in SVN revision 369. The ITDs are now outputting correctly, provided that you follow the expected conventions: "id" and "version" fields must not have a private access modifier (suggest making it package) "id" and "version" fields should be correct annotated with the relevant JPA annotation "id" and "version" fields should have accessors and mutators with a public access modifier If you do this, the intended model will work. Below is a sample script that illustrates correct behaviour and also the hand-edited abstract superclass. project --topLevelPackage com.abstracttest --projectName abstracttest persistence setup --provider OPENJPA --database HYPERSONIC_IN_MEMORY entity --name ~.domain.AbstractBaseEntity -- abstract --mappedSuperclass field number id --type java.lang. Long field number version --type java.lang. Integer entity --name ~.domain.Person -- extends ~.domain.AbstractBaseEntity field string --fieldName firstName --notNull test integration ~.domain.Person package com.abstracttest.domain; import javax.persistence.Entity; import org.springframework.roo.addon.javabean.RooJavaBean; import org.springframework.roo.addon.tostring.RooToString; import org.springframework.roo.addon.entity.RooEntity; import javax.persistence.MappedSuperclass; @Entity @RooJavaBean @RooToString @RooEntity @MappedSuperclass public abstract class AbstractBaseEntity { @javax.persistence.Id @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO) @javax.persistence.Column(name = "id" ) protected Long id; @javax.persistence.Version @javax.persistence.Column(name = "version" ) protected Integer version; public Long getId() { return id; } public void setId( Long id) { this .id = id; } public Integer getVersion() { return version; } public void setVersion( Integer version) { this .version = version; } }

          People

          • Assignee:
            Ben Alex
            Reporter:
            Mike J
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: