Announcement Announcement Module
Collapse
No announcement yet.
generate controller for annotated class? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • generate controller for annotated class?

    I (think) I have followed all the steps in the tutorial:

    1.. hibernate.cfg.xml declares my annotated classes

    DataSource.groovy
    Code:
    import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration
    dataSource {
        configClass = GrailsAnnotationConfiguration.class
        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 {
                configClass = GrailsAnnotationConfiguration.class
                dbCreate = "create-drop" // one of 'create', 'create-drop','update'
                url = "jdbc:hsqldb:mem:devDB"
            }
        }
        test {
            dataSource {
                dbCreate = "update"
                url = "jdbc:hsqldb:mem:testDb"
            }
        }
        production {
            dataSource {
                dbCreate = "update"
                url = "jdbc:hsqldb:file:prodDb;shutdown=true"
            }
        }
    }
    my annotated class is in src/java/package

    when I run generate-controller with classname or with fq class name I allways get the error

    No domain class found for name

    What am I missing?

  • #2
    Try deleting the hibernate.cfg.xml - you shouldn't need it and it may be causing problems. You also don't need the second configClass declaration. And finally, this
    Code:
    dataSource {
        configClass = GrailsAnnotationConfiguration
        ...
    }
    is sufficient, i.e. you don't need the '.class' at the end. GrailsAnnotationConfiguration is a class literal in the above code.

    Hope that helps.

    Comment


    • #3
      Peter,

      Thanks for your input. I have done as you suggested, but still face the same problem, unfortunately.

      The domain I am trying to generate a controller for looks like this

      Code:
      package com.scrumtious.repository;
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import java.util.Date;
      
      @Entity
      public class Defect {
          private String description;
          private Date foundOn;
          private Date fixedOn;
          private String buildNumber;
          private String cause;
          private String resolution;
          private long id;
      
          @Id
          @Column(name="DEFECT_ID")
          public long getId() {
              return id;
          }
      
          public void setId(long id) {
              this.id = id;
          }
      
          @Column(name="DEFECT_DESCRIPTION")
          public String getDescription() {
              return description;
          }
      
          public void setDescription(String description) {
              this.description = description;
          }
      
          @Column(name="FOUND_ON")
          public Date getFoundOn() {
              return foundOn;
          }
      
          public void setFoundOn(Date foundOn) {
              this.foundOn = foundOn;
          }
      
          @Column(name = "FIXED_ON")
          public Date getFixedOn() {
              return fixedOn;
          }
      
          public void setFixedOn(Date fixedOn) {
              this.fixedOn = fixedOn;
          }
      
          @Column(name="BUILD_NUMBER")
          public String getBuildNumber() {
              return buildNumber;
          }
      
          public void setBuildNumber(String buildNumber) {
              this.buildNumber = buildNumber;
          }
      
          @Column(name="CAUSE")
          public String getCause() {
              return cause;
          }
      
          public void setCause(String cause) {
              this.cause = cause;
          }
      
          @Column(name="RESOLUTION")
          public String getResolution() {
              return resolution;
          }
      
          public void setResolution(String resolution) {
              this.resolution = resolution;
          }
      }
      I started off using the hibernate Entity annotation then switched to the javax persistence one (yes I'm clutching at straws).

      I'm using grails 1.3.4 and I get this error both from the command line and from within my ide.

      Can you think of anything else?

      Thanks

      David

      Comment


      • #4
        I apologise, I was wrong about the hibernate.cfg.xml. I got this working with JPA annotations. Your hibernate.cfg.xml needs to contains something like:
        Code:
        <?xml version='1.0' encoding='UTF-8'?>
        <!DOCTYPE hibernate-configuration PUBLIC
            '-//Hibernate/Hibernate Configuration DTD 3.0//EN'
            'http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd'>
        
        <hibernate-configuration>
        
            <session-factory>
                <mapping package='com.scrumtious.repository' />
        
                <mapping class='com.scrumtious.repository.Defect' />
            </session-factory>
        
        </hibernate-configuration>
        You then need to pass the full name of the domain class to generate-controller:
        grails generate-controller com.scrumtious.repository.Defect
        Hope that helps.

        Comment


        • #5
          Peter,

          That fixed it.

          Thanks

          David

          Comment

          Working...
          X