【问题标题】:Reusing JPA annotated class in Grails在 Grails 中重用 JPA 注释类
【发布时间】:2015-05-07 14:38:52
【问题描述】:

我遵循文档并将我的 JPA 注释类放在 src/main/java 下。

此外,我在conf/hibernate 下放了一个hibernate.cfg.xml,如下所示:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <mapping package="com.damluar" />
        <mapping class="com.damluar.CustomerPropertyEntity"/>
        ...
    </session-factory>
</hibernate-configuration>

我还发现了需要添加的提及

configClass = org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration

致我的DataSource.groovy。

然后我使用脚手架生成控制器和视图。当我启动应用程序或使用console 时,Grails 会抛出异常:

URI
    /dataTypeEntity/index
Class
    groovy.lang.MissingMethodException
Message
    No signature of method: static com.damluar.DataTypeEntity.count() is applicable for argument types: () values: [] Possible solutions: print(java.lang.Object), print(java.io.PrintWriter), wait(), dump(), collect(), find()

看起来 Grails 没有向域类添加持久性方法。

当我启动应用程序时,Grails 还会列出现有的人工制品: 文物

Controllers: 3
Domains: 0

【问题讨论】:

    标签: hibernate grails


    【解决方案1】:

    我在使用 Grails 3.0.1 时遇到了类似的问题,解决方案是将 hibernate.cfg.xml 放入 grails-app/conf(不在休眠子目录中),如 mapping-with-hibernate-annotations-in-grails-3-0-1 中所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-07
      • 2011-09-15
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多