Grails
  1. Grails
  2. GRAILS-7851

Grails 2.0.0M1 Domain Class named Environment

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-M1
    • Fix Version/s: 2.0.1
    • Component/s: Converters
    • Labels:
    • Environment:
      Fedora 15 x86_64; Java JDK 1.6.0u24

      Description

      Error:

      Cannot convert value of type
      [org.springframework.web.context.support.StandardServletEnvironment]
      to required type [com.thig.qardi.model.Environment] for property
      'environment': no matching editors or conversion strategy found
      

      Domain Classes:

      class Server {
            static belongsTo = Environment
            static hasMany = [programs:ProgramType]
      
            Environment environment
            String name
            String hostname
            Integer port = 33335
      
        static constraints = {
                    name nullable:false,blank:false
                    hostname nullable:false,blank:false
                    port nullable:false,blank:false
                    environment nullable: false
        }
      }
      class Environment {
            String name
      
            static hasMany = [servers:Server]
      
        static constraints = {
                    name nullable: false, blank: false, unique: true
        }
      
      }
      

      Produces the error:
      def server = new Server()


      Graeme's response: "Hmm it seems Spring 3.1 defines a bean named environment which is the current Spring profile."

        Activity

        Hide
        Rob Nielsen added a comment -

        A seemingly related issue with a different error message is a field in a Domain object with the name of 'environment' (even if the class is not Environment).

        class Author {
        }
        class Book {
            Author environment
        }
        class TestController {
            def index() {
                new Book()
                render "OK"
            }
        }
        
        

        fails with Class: java.lang.IllegalArgumentException Message: argument type mismatch

        and this in the log

        | Error 2011-12-20 13:48:13,868 ["http-bio-8080"-exec-1] ERROR errors.GrailsExceptionResolver  - IllegalArgumentException occurred when processing request: [GET] /domain-issue/test
        argument type mismatch. Stacktrace follows:
        Message: argument type mismatch
           Line | Method
        ->>   8 | index   in batchtool.TestController
        

        Took a while to track it down since it didn't mention environment at all in the error.

        Show
        Rob Nielsen added a comment - A seemingly related issue with a different error message is a field in a Domain object with the name of 'environment' (even if the class is not Environment). class Author { } class Book { Author environment } class TestController { def index() { new Book() render "OK" } } fails with Class: java.lang.IllegalArgumentException Message: argument type mismatch and this in the log | Error 2011-12-20 13:48:13,868 [ "http-bio-8080" -exec-1] ERROR errors.GrailsExceptionResolver - IllegalArgumentException occurred when processing request: [GET] /domain-issue/test argument type mismatch. Stacktrace follows: Message: argument type mismatch Line | Method ->> 8 | index in batchtool.TestController Took a while to track it down since it didn't mention environment at all in the error.
        Hide
        Ed Young added a comment -

        yes, the name collision is probably related to the addition of
        org.springframework.core.env
        Interface Environment

        In Spring 3.1
        http://static.springsource.org/spring/docs/3.1.0.RELEASE/javadoc-api/

        In the above example
        org.springframework.web.context.support
        Class StandardServletEnvironment

        And in our case this is a large problem, because it's looking like we'll have to refactor out the use of our Environment domain which is one of our core domain classes in a very large project, unless there's a better way to deal with it.

        Show
        Ed Young added a comment - yes, the name collision is probably related to the addition of org.springframework.core.env Interface Environment In Spring 3.1 http://static.springsource.org/spring/docs/3.1.0.RELEASE/javadoc-api/ In the above example org.springframework.web.context.support Class StandardServletEnvironment And in our case this is a large problem, because it's looking like we'll have to refactor out the use of our Environment domain which is one of our core domain classes in a very large project, unless there's a better way to deal with it.
        Hide
        Graeme Rocher added a comment -

        We're researching ways to fix this problem

        Show
        Graeme Rocher added a comment - We're researching ways to fix this problem
        Hide
        Peter Ledbrook added a comment -

        I can eliminate the error by adding the method:

        void setEnvironment(org.springframework.core.env.Environment env) {}
        

        to the class that has the environment property. We don't know whether this has any side-effects though, so if people could try it out, that would be great.

        Show
        Peter Ledbrook added a comment - I can eliminate the error by adding the method: void setEnvironment(org.springframework.core.env.Environment env) {} to the class that has the environment property. We don't know whether this has any side-effects though, so if people could try it out, that would be great.
        Hide
        Sami Ubaissi added a comment -

        I am having the same problem, and I am using Grails 2.1.1.

        Show
        Sami Ubaissi added a comment - I am having the same problem, and I am using Grails 2.1.1.

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Dan Woods
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development