在学习教程以开始学习Grails时,我犯了一个错误并运行:
grails create-domain-class com.FooBar
代替:
grails create-domain-class com.acme.FooBar
显而易见,我犯了一个错误,因此尝试了以下操作:
此后,该应用程序无法运行,并报告以下错误:
org.hibernate.DuplicateMappingException: duplicate import: FooBar refers to both com.acme.FooBar and com.FooBar (try using auto-import="false")
将以下代码添加到com.acme.FooBar之后:
...
static mapping = {
autoImport false
}
...
该应用程序现在可以按预期运行。
但是,作为有经验的Java开发人员,偶尔会重构软件包,我想了解如何做到这一点而不会引起DuplicateMappingException或诉诸“autoImport false”解决方案。
谢谢。
最佳答案
你不应该那样做
static mapping = {
autoImport false
}
因此,您说过不要仅按名称检查域,也要查找软件包。因此,一旦这样做,您将不得不在查询/ hqls中使用类的完全限定名称,这有时会发痒。
您应该完全删除域,即
- remove the Domain
- remove the view folder creating by default with very same name and so do the controller
- Now, do grails clean-all(Make it a thumb rule to use grails clean-all first for any issue unexpectedly occuring).
- To be more accurate do remove target directory from your project and then do run grails run-app.
我做了很多相同的事情,并通过上述步骤解决了它。
希望能帮助到你。
关于exception - 域类的Grails软件包更改导致DuplicateMappingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33389859/