Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-3086

Naming conflict with local variable "document" conflicts with defining an entity type named "Document" which is solr searchable

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 1.2.1.RELEASE
    • Fix Version/s: 1.2.2.RELEASE
    • Component/s: @ ROO SHELL
    • Labels:
    • Environment:
      STS 2.8.1.RELEASE (64 bit on 64 bit Windows 7 Professional)

      Description

      Below is and excerpt from a roo script that should reproduce the problem:

      /* ====== Document ====== */
      entity jpa --class com.bigcorp.domain.foundation.Document --testAutomatically
      field string --fieldName name --sizeMax 60
      solr setup
      solr all

      The resulting method in the ITD, Document_Roo_SolrSearch.aj is roughly (I deleted some lines to keep the script minimal):
      @Async
      public static void Document.indexDocuments(Collection<Document> documents) {
      List<SolrInputDocument> documents = new ArrayList<SolrInputDocument>();
      for (Document document : documents)

      { SolrInputDocument sid = new SolrInputDocument(); sid.addField("id", "document_" + document.getId()); sid.addField("document.name_s", document.getName()); sid.addField("document.id_l", document.getId()); // Add summary field to allow searching documents for objects of this type sid.addField("document_solrsummary_t", new StringBuilder().append(document.getEntityType()).append(" ").append(document.getEntityId()).append(" ").append(document.getName()).append(" append(" ").append(document.getId())); documents.add(sid); }

      try

      { SolrServer solrServer = solrServer(); solrServer.add(documents); solrServer.commit(); }

      catch (Exception e)

      { e.printStackTrace(); }

      }

      where the offending declaration is "documents: in the line: List<SolrInputDocument> documents = new ArrayList<SolrInputDocument>();
      (and the variable in the following line)

      I first thought this would just be a minor annoyance, since an easy workaround existed: I could push in that method to the Document.java file and change the name of the conflicting variable. However when I tried that I received the message: "No crosscutting model available. Rebuild Project" Unfortunately, that an other errors prevents a successful rebuild of the project.

      Another workaround would be to rename the entity type: "Document" to "XXXDocument" or something other than "Document", but that creates a some work to provide "Document" in the user interface while the underlying entity type is "XXXDocument". That is direction I'm taking, but some else is likely to run into the same issue.

        Attachments

          Activity

            People

            Assignee:
            stewarta Alan Stewart
            Reporter:
            briancarroll Brian Carroll
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: