Announcement Announcement Module
Collapse
No announcement yet.
Non-existent 'Employee' Type in JavaBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Non-existent 'Employee' Type in JavaBean

    I just picked up Roo 1.1.1, and decided to crank up a new project to play around with it. However, I've run into a weird problem that I'm not entirely sure is the fault of my own ignorance! Any help would be greatly appreciated.

    Here is a Roo script that I've used to reproduce the problem (attached as 'roo.script.txt'):

    Code:
    // Spring Roo 1.1.1.RELEASE [rev 156ccd6] log opened at 2011-01-12 09:52:47
    download status
    download accept terms of use
    project --topLevelPackage example
    persistence setup --provider DATANUCLEUS --database GOOGLE_APP_ENGINE 
    entity --class ~.domain.Bar
    entity --class ~.domain.Foo 
    field set --fieldName bars --type ~.domain.Bar
    exit
    // Spring Roo 1.1.1.RELEASE [rev 156ccd6] log closed at 2011-01-12 09:57:44
    Nothing too exciting here: create a Google AppEngine project with two entities, and create a one-to-many from the 'Foo' type to the 'Bar' type. The script runs without an error and exits cleanly.

    However, look at the generated Foo_Roo_JavaBean.aj file; specifically the setBars(Set<Bar> bars) method. Mine looks like this:

    Code:
       public void Foo.setBars(Set<Bar> bars) {
            Set<example.domain.Bar> localBars = new HashSet<example.domain.Bar>();
            List<Long> longIds = new ArrayList<Long>();
            for (Key key : barsKeys) {
                if (!longIds.contains(key.getId())) {
                    longIds.add(key.getId());
                }
            }
            for (Employee entity : bars) {
                if (!longIds.contains(entity.getId())) {
                    longIds.add(entity.getId());
                    barsKeys.add(KeyFactory.createKey(Bar.class.getName(), entity.getId()));
                }
                localBars.add(entity);
            }
            this.bars = localBars;
        }
    What is that second 'for' loop doing? Where did the Employee type come from? Shouldn't that be "for (Bar bar : bars) {" ... ?

    Any help would be greatly appreciated!


    Thanks,

    Peter

  • #2
    Found it in the source code....

    I decided to dig into this issue a little bit more by grabbing the Roo source and seeing if it that would shed any light on the 'Employee' type being generated in an AspectJ file under certain circumstances.

    Volia. Have a look at ...

    /addon-javabean/src/main/java/or/springframework/roo/addon/javabean/JavaBeanMetadata.java


    ... within the ...

    private InvocableMemberBodyBuilder getEntityCollectionMutatorBody(FieldMetadata field, JavaSymbolName entityIdsFieldName)

    ... method. In the source from HEAD that I cloned today, look around line 364, when the method is building the body of the AspectJ file:

    Code:
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.appendFormalLine("for (Employee entity : " + entityCollectionName +") {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("if (!longIds.contains(entity.getId())) {");
    bodyBuilder.indent();
    (emphasis mine) I'm guessing this made it past unit tests because the test uses the Employee type itself. You can see it in the FishEye source browser as well here:

    https://fisheye.springsource.org/bro...a.java?hb=true


    Can someone confirm my sanity here? Surely that is a bug?


    Thanks,

    Peter

    Comment


    • #3
      FYI -- created a JIRA isue for this:

      https://jira.springframework.org/browse/ROO-1983

      Comment


      • #4
        &quot;Employee entity&quot;

        this is clearly a bug also a funny one but it is a problem. Did found any work around for it? otherwise it renders the release generally unusable :-(

        Comment


        • #5
          Minor problem

          @pwagener: Thanks for raising an issue in jira and for providing a fix, but you assigned it as Priority "minor", which means there is an easy work around. Does compiling the source myself is an easy workaround? Or do I miss something?
          For me Roo is really a quantum leap, but with this "minor" problem it is useless at the moment. I wonder, that other people obviously do not have problems with that.

          /Klaus

          Comment


          • #6
            Sorry everyone - I fixed this specific issue in ROO-1983. However, there is another regression-type bug in the same code in that collection elements that are @RooEntity's are not being considered for inclusion as GAE-interested fields. The script will not generate the same code as listed above. This will be fixed soon.

            Comment


            • #7
              The issue I described above is fixed now (https://jira.springsource.org/browse/ROO-2078). Please test and let me know here.
              Thanks

              Comment


              • #8
                Originally posted by klausJ View Post
                you assigned it as Priority "minor", which means there is an easy work around. Does compiling the source myself is an easy workaround? Or do I miss something?
                Have you tried the workaround of creating an Employee class in the same package as the affected entity?

                Comment


                • #9
                  Originally posted by andrews View Post
                  Have you tried the workaround of creating an Employee class in the same package as the affected entity?
                  Not yet, but I seriously thought about that.

                  Comment


                  • #10
                    Tried build snapshot with no success.

                    Originally posted by Alan Stewart View Post
                    The issue I described above is fixed now (https://jira.springsource.org/browse/ROO-2078). Please test and let me know here.
                    Thanks
                    I tried with ROO/spring-roo-1.1.2.BUILD-SNAPSHOT_20110207.052044-2c2604a.zip
                    After doing a lot of work, it stopped with the following error (I didn't try to download anything manually so far). Looks more like a general build error, not related to our issue.

                    [INFO] ------------------------------------------------------------------------
                    [Thread-9] [ERROR] BUILD ERROR
                    [Thread-9] [INFO] ------------------------------------------------------------------------
                    [Thread-9] [INFO] Failed to resolve artifact.
                    [Thread-9] obe roo>
                    [Thread-9] Missing:
                    [Thread-9] ----------
                    [Thread-9] 1) org.springframework.roo:org.springframework.roo.an notations:jar:1.1.2.BUILD-SNAPSHOT
                    [Thread-9] obe roo>
                    [Thread-9] Try downloading the file manually from the project website.
                    [Thread-9] obe roo>
                    [Thread-9] Then, install it using the command:
                    [Thread-9] mvn install:install-file -DgroupId=org.springframework.roo -DartifactId=org.springframework.roo.annotations -Dversion=1.1.2.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file
                    [Thread-9] obe roo>
                    [Thread-9] Alternatively, if you host your own repository you can deploy the file there:
                    [Thread-9] mvn deploy:deploy-file -DgroupId=org.springframework.roo -DartifactId=org.springframework.roo.annotations -Dversion=1.1.2.BUILD-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
                    [Thread-9] obe roo>
                    [Thread-9] Path to dependency:
                    [Thread-9] 1) de.klangverfolger.probenplanrobenplan:war:0.1.0.BUILD-SNAPSHOT
                    [Thread-9] 2) org.springframework.roo:org.springframework.roo.an notations:jar:1.1.2.BUILD-SNAPSHOT
                    [Thread-9] obe roo>
                    [Thread-9] ----------
                    [Thread-9] 1 required artifact is missing.
                    [Thread-9] obe roo>
                    [Thread-9] for artifact:
                    [Thread-9] de.klangverfolger.probenplanrobenplan:war:0.1.0.BUILD-SNAPSHOT
                    [Thread-9] obe roo>
                    [Thread-9] from the specified remote repositories:
                    [Thread-9] spring-maven-milestone (http://maven.springframework.org/milestone),
                    [Thread-9] central (http://repo1.maven.org/maven2),
                    [Thread-9] spring-roo-repository (http://spring-roo-repository.springsource.org/release),
                    [Thread-9] DataNucleus_2 (http://www.datanucleus.org/downloads/maven2/),
                    [Thread-9] maven-gae-plugin-repo (http://maven-gae-plugin.googlecode.com/svn/repository),
                    [Thread-9] spring-maven-release (http://maven.springframework.org/release),
                    [Thread-9] JBoss Repo (https://repository.jboss.org/nexus/content/repositories/releases)
                    [Thread-9] obe roo>

                    Comment


                    • #11
                      I tried with ROO/spring-roo-1.1.2.BUILD-SNAPSHOT_20110207.052044-2c2604a.zip
                      Can you get the source code and build? The error is unrelated to GAE.

                      Comment


                      • #12
                        Originally posted by Alan Stewart View Post
                        Can you get the source code and build? The error is unrelated to GAE.
                        I have no idea how to do that.

                        Comment


                        • #13
                          Originally posted by Alan Stewart View Post
                          Can you get the source code and build? The error is unrelated to GAE.
                          Hi Alan,

                          I just grabbed HEAD and ran Roo through the attached script (effectively the same one attached to my original post). The 'Employee' type is obviously now fixed (thanks!), but an attempt to package the generated project failed with the following:

                          Code:
                          ~.domain.Foo roo> perform package
                          ... (removed for clarity)
                          [Thread-7] [ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.0:compile (default) on project example: Compiler errors :
                          [Thread-7] [ERROR] error at sb.append("Bars: ").append(getBars() == null ? "null" : getBars().size());
                          [Thread-7] [ERROR] 
                          [Thread-7] [ERROR] /Users/pwagener/Devel/RooSpike/src/main/java/example/domain/Foo_Roo_ToString.aj:12:0::0 The method getBars() is undefined for the type Foo
                          [Thread-7] [ERROR] error at sb.append("Bars: ").append(getBars() == null ? "null" : getBars().size());
                          [Thread-7] [ERROR] 
                          [Thread-7] [ERROR] /Users/pwagener/Devel/RooSpike/src/main/java/example/domain/Foo_Roo_ToString.aj:12:0::0 The method getBars() is undefined for the type Foo
                          [Thread-7] [ERROR] error at declare @field: * Foo.bars: ;
                          [Thread-7] [ERROR] 
                          [Thread-7] [ERROR] /Users/pwagener/Devel/RooSpike/src/main/java/example/domain/Foo_Roo_JavaBean.aj:20:0::0 Syntax error on token ":", MarkerAnnotation expected after this token
                          [Thread-7] [ERROR] -> [Help 1]
                          ... (and the rest of the typical maven build failure)
                          Looking at the generated source for Foo_Roo_JavaBean.aj, the lines in question are:

                          Code:
                          privileged aspect Foo_Roo_JavaBean {
                              
                              declare @field: * Foo.bars: -@ManyToMany(cascade = CascadeType.ALL);
                              
                              declare @field: * Foo.bars: ;
                              
                              private Set<Key> Foo.barsKeys = new HashSet<Key>();
                          
                          ...
                          Line 20 is the second 'declare @field'. I will readily admit I'm not an AspectJ expert (hoping Roo can do that for me), but apparently that generated field declaration isn't quite what is expected. Let me know if you need any more info.


                          Thanks,

                          Peter

                          Comment


                          • #14
                            declare @field: * Foo.bars: -@ManyToMany(cascade = CascadeType.ALL);
                            This was also fixed a couple of weeks ago, so I am surprised you are getting this. When removing annotations, AspectJ only requires the name of the annotation and will give an error is attributes are present.

                            I will have another look.

                            Comment


                            • #15
                              Hi Alan,

                              Sorry -- my mistake. When I rebuilt Roo from the updated source, I only did 'mvn install', which apparently didn't build with all the newer code. Might be a bug in the build process, or might've just been something I mucked up in there.

                              Regardless, building with 'mvn clean install' and re-running through this test script now works just fine. Thanks again for the help.


                              Peter

                              Comment

                              Working...
                              X