在Grails中重用JPA注释类 [英] Reusing JPA annotated class in Grails

查看:84
本文介绍了在Grails中重用JPA注释类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了文档,并将我的JPA批注类放在 src / main / java 下。 b
$ b

我在 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

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

  URI 
/ dataTypeEntity / index

groovy.lang.MissingMethodException
消息
无方法签名:static com.damluar.DataTypeEntity.count()适用参数类型:()values:[]可能的解决方案:print(java.lang.Object),print(java.io.PrintWriter),wait(),dump(),collect(),find()

看起来Grails不会将持久性方法添加到域类中。



当我启动应用程序时,Grails列出了现有的工件:
Artefacts

 控制器:3 
域名:0


解决方案

Grails 3.0.1,解决方案是在 grails-app / conf 中放入 hibernate.cfg.xml 在hibernate子目录内),如 mapping-with-hibernate-annotations-in-grails-3-0-1


I followed the documentation and put my JPA annotated classes under src/main/java.

In addition I put a hibernate.cfg.xml under conf/hibernate which looks like this:

<?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>

I also found mentions that I need to add

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

to my DataSource.groovy.

Then I generated controllers and views using scaffolding. When I start the app or use a console, Grails throws exception:

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()

It looks like Grails doesn't add persistence methods to the domain classes.

Also when I start the application Grails lists existing artefacts: Artefacts

Controllers: 3
Domains: 0

解决方案

I had a similar issue with Grails 3.0.1, and the solution was to put hibernate.cfg.xml in grails-app/conf (not inside a hibernate subdirectory) as described in mapping-with-hibernate-annotations-in-grails-3-0-1.

这篇关于在Grails中重用JPA注释类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆