Announcement Announcement Module
Collapse
No announcement yet.
Controller not finding domain class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controller not finding domain class

    I have been attempting to add some new functionality to an existing grails application. I started by adding a simple domain class through the console:

    Code:
    package com.xfitlog
    
    class ProgramType {
    	String name
    	String description
    		
        static constraints = {
    		name( nullable: false, unique: true )
    		description( nullable: false )
        }
    	
    	String toString() {
    		"${name}"	
    	}
    }
    I then created a simple controller through the console:

    Code:
    package com.xfitlog
    
    class ProgramTypeController {
    
        static scaffold = ProgramType
    }
    When I execute grails run-app and navigate to the controller page I get this error:

    ERROR plugins.DefaultGrailsPlugin - Cannot generate controller logic for scaffolded class class com.xfitlog.ProgramType. It is not a domain class!

    Does anyone have any idea what could be causing this in an application that is already up and running?

  • #2
    When you say you added a simple domain class "through the console", what do you mean exactly? In other words, what were your exact steps? Were you in interactive mode?

    Comment


    • #3
      I first created the domain class using the grails create-domain-class command in the windows command prompt. I then opened up the .groovy file that was created and edited it. After that I created the controller through the windows command prompt with grails create-controller. I then opened up the controller file created and edited it.

      Comment


      • #4
        I've also noticed that the controller does not appear on the Available Controllers list after the project builds. If I make any change to the controller file then save it I will get the following error:

        [Thread-610] ERROR plugins.DefaultGrailsPlugin - Cannot generate controller logic for scaffolded class class com.xfitlog.ProgramType. It is not a domain class!

        I think that something has gone wrong with the grails files or hibernate, but I'm not sure where to start looking.

        Comment


        • #5
          What version of Grails? Are you doing any of these steps from an IDE? How are you starting the application?

          Comment


          • #6
            I'm using version 1.3.7 and I haven't had any problems with it up until I tried to create this new domain class. All of these steps are through the Windows Command Prompt and Notepad++.

            Thanks

            Comment


            • #7
              So you have other domain classes that you can scaffold fine? If so, that would indicate issues with the domain class definition. Perhaps its name. Try a different class name, such as ProgType. If that doesn't work, try adding this line to your logging configuration:

              Code:
              debug  'org.codehaus.groovy.grails.orm.hibernate'
              You'll have to remove that package from the 'error' or 'warn' line at the same time.

              Comment


              • #8
                I changed the name of the domain and controller to 'ProgType' and got the same error.

                Can you tell me where the logging configuration file is?

                Comment


                • #9
                  grails-app/conf/Config.groovy - you'll find a line starting 'log4j = {' which is where the logging configuration is.

                  Comment


                  • #10
                    Thanks!

                    I've got the Config.groovy logging code set and I've restarted the app. The debug spit out a ton of stuff but I don't see anything that mentions 'ProgramType'.

                    What do I need to look for in the debug log?

                    Comment


                    • #11
                      Something like this:

                      <pre>

                      2011-08-09 16:12:16,442 [Thread-10] DEBUG cfg.GrailsAnnotationConfiguration - [GrailsAnnotationConfiguration] [1] Grails domain classes to bind to persistence runtime
                      2011-08-09 16:12:16,456 [Thread-10] DEBUG cfg.GrailsAnnotationConfiguration - [GrailsAnnotationConfiguration] Binding persistent class [org.example.ProgramType]
                      2011-08-09 16:12:16,457 [Thread-10] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] Mapping Grails domain class: org.example.ProgramType -> program_type
                      2011-08-09 16:12:16,479 [Thread-10] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] bound property [id] to column name [id] in table [program_type]
                      2011-08-09 16:12:16,486 [Thread-10] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] bound property [version] to column name [version] in table [program_type]
                      2011-08-09 16:12:16,488 [Thread-10] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] Binding persistent property [description]
                      2011-08-09 16:12:16,491 [Thread-10] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] Binding property [description] as SimpleValue
                      2011-08-09 16:12:16,491 [Thread-10] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] bound property [description] to column name [description] in table [program_type]
                      2011-08-09 16:12:16,491 [Thread-10] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] Binding persistent property [name]
                      2011-08-09 16:12:16,492 [Thread-10] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] Binding property [name] as SimpleValue
                      2011-08-09 16:12:16,492 [Thread-10] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] bound property [name] to column name [name] in table [program_type]
                      2011-08-09 16:12:16,720 [Thread-10] INFO hibernate.ConfigurableLocalSessionFactoryBean - Building new Hibernate SessionFactory
                      2011-08-09 16:12:16,720 [Thread-10] DEBUG cfg.GrailsAnnotationConfiguration - [GrailsAnnotationConfiguration] Setting context class loader to Grails GroovyClassLoader
                      2011-08-09 16:12:17,160 [Thread-10] INFO hibernate.GrailsHibernateTransactionManager - Using DataSource [org.springframework.jdbc.datasource.TransactionAwa reDataSourceProxy@1806e9d2] of Hibernate SessionFactory for HibernateTransactionManager
                      </pre>

                      Comment


                      • #12
                        I'm seeing lines like that for all of my other domain classes but nothing for 'ProgramType'. It almost seems like hibernate isn't seeing it at all.

                        Comment


                        • #13
                          I've changed the code in my controller 3 times. Each time I get a different error message.

                          If I use this line to get the scaffolding:
                          Code:
                          static scaffold = ProgramType
                          I get this error:

                          2011-08-09 16:22:58,570 [Thread-58] ERROR plugins.DefaultGrailsPlugin - Cannot generate controller logic for scaffolded class class com.xfitlog.ProgramType. It is not a domain class!
                          If I use this code:

                          Code:
                          def scaffold = true
                          I get this error:

                          2011-08-09 16:20:53,602 [Thread-33] ERROR plugins.DefaultGrailsPlugin - Cannot generate controller logic for scaffolded class true. It is not a domain class!
                          2011-08-09 16:21:18,211 [http-8080-1] ERROR errors.GrailsExceptionResolver - Exception occurred when processing request: [GET] /xfitlog/programType/scaffold
                          Stacktrace follows:
                          java.lang.ClassCastException: java.lang.Boolean cannot be cast to groovy.lang.Closure
                          at java.lang.Thread.run(Thread.java:619)
                          and if I use the code generated by the generate all command I get this error:

                          2011-08-09 16:25:28,272 [http-8080-5] ERROR errors.GrailsExceptionResolver - Exception occurred when processing request: [GET] /xfitlog/programType/list
                          Stacktrace follows:
                          groovy.lang.MissingMethodException: No signature of method: static com.xfitlog.ProgramType.list() is applicable for argument types: (org.codehaus.groovy.grails.web.servlet.mvc.Grails ParameterMap) valu
                          es: [[action:list, controllerrogramType, max:10]]
                          Possible solutions: is(java.lang.Object), wait(), wait(long), print(java.io.PrintWriter), split(groovy.lang.Closure), use([Ljava.lang.Object
                          at com.xfitlog.ProgramTypeController$_closure2.doCall (ProgramTypeController.groovy:31)
                          at com.xfitlog.ProgramTypeController$_closure2.doCall (ProgramTypeController.groovy)
                          at java.lang.Thread.run(Thread.java:619)

                          Comment


                          • #14
                            Have you tried removing your 'target' directory and possibly recreating the ProgramType domain class? All the above errors mean the same thing: Grails is not seeing ProgramType as a domain class. Is there no difference between it and the other domain classes?

                            Comment


                            • #15
                              I removed the 'target' directory and rebuilt the project. Resulted in the same error.

                              I tried to create a more complex domain object before 'ProgramType'. That is when I first noticed the error. I created 'ProgramType' as a very simple object to try and isolate the problem.

                              I'm beginning to wonder If I screwed the project up by introducing a MySQL DB connection in the test environment. Here is my DataSource.groovy code. Let me know if anything looks amiss.

                              Code:
                              dataSource {
                                  pooled = true
                                  driverClassName = "org.hsqldb.jdbcDriver"
                                  username = "sa"
                                  password = ""
                              }
                              hibernate {
                                  cache.use_second_level_cache = true
                                  cache.use_query_cache = true
                                  cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
                              }
                              // environment specific settings
                              environments {
                                  development {
                                      dataSource {
                                          dbCreate = "update" // one of 'create', 'create-drop','update'
                                          url = "jdbc:hsqldb:file:devDb;shutdown=true"
                                      }
                                  }
                                  test {
                                      dataSource {
                              			pooled = true
                              			driverClassName = "com.mysql.jdbc.Driver"
                              			url = "jdbc:mysql://localhost/public" //"jdbc:mysql://localhost/xfitlog"
                              			dbCreate = "update"
                              			username = "sa"
                              			password = ""
                              			dialect = org.hibernate.dialect.MySQL5InnoDBDialect
                                      }
                                  }
                                  production {
                                      dataSource {
                                          dbCreate = "update"
                              			url = "jdbc:hsqldb:file:prodDb;shutdown=true"
                              			// AWS RDS
                                          //url = "jdbc:mysql://ironworkslog.cat4owdsmbkz.us-east-1.rds.amazonaws.com:3306/ironworkslog"
                              			//Instance: IronWorksLog
                              			//UserName: ironworks_user
                              			//Password: xfitLogBitch
                                      }
                                  }
                              }
                              Thanks for your continued help!!

                              Comment

                              Working...
                              X