Grails,app-engine,jpa - 初学者在使用grails时遇到问题

时间:2010-04-24 09:19:10

标签: google-app-engine grails jpa

我正在尝试通过以下几个教程来了解使用Google App Engine和JPA的Grails:

我有grails 1.3.0 RC 2和App Engine SDK 1.3.3,我正在使用Windows 7.我尝试的步骤是:

  1. grails create-app appname
  2. cd appname
  3. grails install-plugin app-engine。当被问及jdo / jpa时,我回答jpa。它似乎是自动安装gorm-jpa插件,虽然教程都建议手动安装gorm-jpa。
  4. grails install-plugin gorm-jpa(以防万一)
  5. grails create-domain-class test.Person
  6. 编辑grails-app/domain/test/Person.groovy以添加姓名和地址字段:

    package test
    import javax.persistence.*;
    
    // import com.google.appengine.api.datastore.Key;
    @Entity
    class Person implements Serializable {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id
    
      @Basic
      String name
    
      @Basic
      String address
    
      static constraints = {
        id visible:false
      }
    }
    
  7. grails generate-all test.Person

  8. 我在最后一步中遇到错误:

    C:\Users\John\Workspaces\STS\appname>grails generate-all test.Person
    Welcome to Grails 1.3.0.RC2 - http://grails.org/
    Licensed under Apache Standard License 2.0
    Grails home is set to: C:\Users\John\Downloads\grails-1.3.0.RC2\grails-1.3.0.RC2
    
    Base Directory: C:\Users\John\Workspaces\STS\appname
    Resolving dependencies...
    Dependencies resolved in 493ms.
    Running script C:\Users\John\Downloads\grails-1.3.0.RC2\grails-1.3.0.RC2\scripts\GenerateAll.groovy
    Environment set to development
         [copy] Copied 4 empty directories to 2 empty directories under C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources
         [copy] Copied 4 empty directories to 2 empty directories under C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources
         [copy] Copied 1 empty directory to 1 empty directory under C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources
        [mkdir] Created dir: C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\classes
      [groovyc] Compiling 12 source files to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\classes
    Note: C:\Users\John\.grails\1.3.0.RC2\projects\appname\plugins\gorm-jpa-0.7.1\src\java\org\grails\jpa\domain\JpaGrailsDomainClass.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
      [groovyc] Compiling 8 source files to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\classes
        [mkdir] Created dir: C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources\grails-app\i18n
    [native2ascii] Converting 13 files from C:\Users\John\Workspaces\STS\appname\grails-app\i18n to C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources\grails-app\i18n
        [mkdir] Created dir: C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources\plugins\gorm-jpa-0.7.1\grails-app\i18n
        [mkdir] Created dir: C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources\plugins\app-engine-0.8.10\grails-app\i18n
    [native2ascii] Converting 1 file from C:\Users\John\.grails\1.3.0.RC2\projects\appname\plugins\gorm-jpa-0.7.1\grails-app\i18n to C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources\plugins\gorm
    -jpa-0.7.1\grails-app\i18n
    [native2ascii] Converting 1 file from C:\Users\John\.grails\1.3.0.RC2\projects\appname\plugins\app-engine-0.8.10\grails-app\i18n to C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources\plugins\a
    pp-engine-0.8.10\grails-app\i18n
         [copy] Copying 1 file to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\classes
         [copy] Copying 2 files to C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources
         [copy] Copied 2 empty directories to 2 empty directories under C:\Users\John\.grails\1.3.0.RC2\projects\appname\resources
         [copy] Copying 1 file to C:\Users\John\.grails\1.3.0.RC2\projects\appname
        [mkdir] Created dir: C:\Users\John\Workspaces\STS\appname\web-app\plugins\app-engine-0.8.10
         [copy] Copying 1 file to C:\Users\John\Workspaces\STS\appname\web-app\plugins\app-engine-0.8.10
         [copy] Copying 1 file to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF
        [mkdir] Created dir: C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\lib
         [copy] Copying 64 files to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\lib
    Configuring persistence for AppEngine
        [mkdir] Created dir: C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\classes\META-INF
         [copy] Copying 1 file to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\classes\META-INF
        [mkdir] Created dir: C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\plugins\app-engine-0.8.10
         [copy] Copying 2 files to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\plugins\app-engine-0.8.10
        [mkdir] Created dir: C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\plugins\gorm-jpa-0.7.1
         [copy] Copying 2 files to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\plugins\gorm-jpa-0.7.1
    Packaging AppEngine jar files
    Enhancing JDO classes
      [enhance] DataNucleus Enhancer (version 1.1.4) : Enhancement of classes
      [enhance] DataNucleus Enhancer completed with success for 1 classes. Timings : input=589 ms, enhance=200 ms, total=789 ms. Consult the log for full details
      [groovyc] Compiling 1 source file to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF\classes
         [copy] Copying 1 file to C:\Users\John\.grails\1.3.0.RC2\projects\appname
         [copy] Copying 1 file to C:\Users\John\Workspaces\STS\appname\web-app\WEB-INF
    Configuring persistence for AppEngine
    Packaging AppEngine jar files
    Enhancing JDO classes
      [enhance] DataNucleus Enhancer (version 1.1.4) : Enhancement of classes
      [enhance] DataNucleus Enhancer completed with success for 1 classes. Timings : input=585 ms, enhance=28 ms, total=613 ms. Consult the log for full details
    Generating views for domain class test.Person ...
    java.lang.reflect.InvocationTargetException
            at SimpleTemplateScript1.run(SimpleTemplateScript1.groovy:43)
            at _GrailsGenerate_groovy.generateForDomainClass(_GrailsGenerate_groovy:85)
            at _GrailsGenerate_groovy$_run_closure1.doCall(_GrailsGenerate_groovy:50)
            at GenerateAll$_run_closure1.doCall(GenerateAll.groovy:42)
            at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
            at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
            at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
            at gant.Gant.withBuildListeners(Gant.groovy:427)
            at gant.Gant.this$2$withBuildListeners(Gant.groovy)
            at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
            at gant.Gant.dispatch(Gant.groovy:415)
            at gant.Gant.this$2$dispatch(Gant.groovy)
            at gant.Gant.invokeMethod(Gant.groovy)
            at gant.Gant.executeTargets(Gant.groovy:590)
            at gant.Gant.executeTargets(Gant.groovy:589)
    Caused by: java.lang.NoClassDefFoundError: org/hibernate/MappingException
            ... 15 more
    Caused by: java.lang.ClassNotFoundException: org.hibernate.MappingException
            at org.codehaus.groovy.tools.RootLoader.findClass(RootLoader.java:156)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:128)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
            ... 15 more
    Error running generate-all: null
    

    我做错了什么?

    我应该咨询哪些日志文件以获取详细信息?

1 个答案:

答案 0 :(得分:1)

似乎使用标准脚手架将可见性设置为false会导致错误。我不得不从这个块中删除中间行,它起作用了:

 static constraints = {
   id visible:false
 }

我认为这是'约定优于配置'的成本之一:隐藏的依赖关系。或者可能是我还在学习......