如何修复 Grails 错误:“未找到名称 PrivacyOptions 的域类。 请重试并输入有效的域名类别名称”

发布于 2024-07-30 14:24:54 字数 616 浏览 1 评论 0原文

我刚刚开始使用 Groovy/Grails。

我向我的项目添加了一个新的域控制器,但生成控制器不喜欢它。

还有其他迹象表明出了问题:如果我运行该应用程序,则数据库中实际上不会为此创建任何表。

我已将 DomainController 减少为一个字符串字段并且没有任何限制,只是为了确保我的规范没有问题。 我还尝试重命名它,以防原始名称(隐私)与某些内容发生冲突。

我确信我的名称正确,并且该文件名为 PrivacyOptions.groovy,并且该类内部也名为 PrivacyOptions。

这是错误:

Running script /opt/local/grails/scripts/GenerateController.groovy
Environment set to development
Domain class not found in grails-app/domain, trying hibernate mapped classes...
No domain class found for name PrivacyOptions. Please try again and enter a valid domain class name

I'm just getting started with Groovy/Grails.

I added a new domain controller to my project, and generate-controller doesn't like it.

There are other indications something's wrong: If I run the app no table is actually created in the database for this.

I've reduced the DomainController to one String field and no constraints, just to make sure there wasn't something wrong with my specification. I also tried renaming it, just in case there was something about the original name (Privacy) that conflicted with something.

I'm sure I have the correct name, and that the file is called PrivacyOptions.groovy and inside the class is also called PrivacyOptions.

Here's the error:

Running script /opt/local/grails/scripts/GenerateController.groovy
Environment set to development
Domain class not found in grails-app/domain, trying hibernate mapped classes...
No domain class found for name PrivacyOptions. Please try again and enter a valid domain class name

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

疧_╮線 2024-08-06 14:24:54

在模型名称之前添加项目名称(也称为模型文件第一行的包名称)。

grails generate-all projectname.Class

经过一小时的绞尽脑汁和谷歌搜索后,这终于对我有用了。

参考:

从 1.2.2 开始,Grails 在默认为您的包中创建工件
项目名称 - 请参阅 http://jira.codehaus.org/browse/GRAILS-5713
因此,您需要运行 grailsgenerate-all srapp.Srmodel
- 伯特

Add the project name (aka the package name from the first line of the model file) before the model name.

grails generate-all projectname.Class

This is the one that finally worked for me, after an hour of head scratching and googling.

ref: http://grails.1312388.n4.nabble.com/Generate-Scaffold-Scripts-Don-t-Work-Getting-No-domain-class-found-Error-td2017858.html#a2017880

As of 1.2.2 Grails creates artifacts in packages that default to your
project name - see http://jira.codehaus.org/browse/GRAILS-5713
So you'd need to run grails generate-all srapp.Srmodel
- Burt

椒妓 2024-08-06 14:24:54

它不是projectname.Class,它必须是dirname.classname。

例如:您的项目名称是 Helloworld,目录是 "grails-app/domain/helloworld/User.groovy" 。 所以,命令是“grailsgenerate-all helloworld.User”,而不是“Helloworld.User”

it's not projectname.Class , it must be dirname.classname .

eg: your projectname is Helloworld, the directory is "grails-app/domain/helloworld/User.groovy" . so , the command is "grails generate-all helloworld.User" ,but not "Helloworld.User"

荆棘i 2024-08-06 14:24:54

很有帮助。 在本教程之后,我遇到了同样的问题,将项目命名为“ trip-planner”,Grails 将域目录生成为“~/trip/planner/”而不是“~/trip-planner/”。 那么 Trip 类的generate-all 命令应该是“grailsgenerate-all tr​​ip.planner.Trip”,

以防有人在项目名称中添加“-”字符。

Great help. I faced the same problem following this tutorial that names the project as "trip-planner" and Grails generates the domain directories as '~/trip/planner/' instead of '~/trip-planner/'. Then the generate-all command for a Trip class should be 'grails generate-all trip.planner.Trip'

Just in case someone adds a '-' character to the project name.

紫罗兰の梦幻 2024-08-06 14:24:54

是的...也为我工作。 我只是将包名称作为我试图为其生成所有内容的类的前缀,并且它起作用了。 所以...

generate-allracetrack.User

确实有点裤子错误,因为所有其他 grails 命令不需要包含包名称:-))

Yep... worked for me too. I just prefixed the package name to the class I was trying to generate-all for and it worked. So ...

generate-all racetrack.User

Bit of a pants bug really since all other grails commands do not require a package name to be included :-))

懵少女 2024-08-06 14:24:54

我不知道你是如何做到这一点的,但也许会帮助你克服困难。

我是否正确地假设您使用“grails create-domain-class”来创建 PrivacyOptions 域对象,并且 Groovy 脚本显示在您的 grails-app/domain 目录中? 您在测试/单元中获得了 PrivacyOptionsTests 吗? 通过了吗? 你添加了一个包吗?

I don't know how you got to this point, but maybe this will help you get over the hump.

Am I correct to assume that you used "grails create-domain-class" to create PrivacyOptions domain object, and the Groovy script showed up in your grails-app/domain directory? Did you get a PrivacyOptionsTests in test/unit? Did that pass? Did you add a package?

盛夏已如深秋| 2024-08-06 14:24:54

关于堆栈跟踪不清楚缺少属性的相关问题:

http://jira.codehaus.org/浏览/GRAILS-1607

related issue about stack trace not being clear for missing properties:

http://jira.codehaus.org/browse/GRAILS-1607

謌踐踏愛綪 2024-08-06 14:24:54

generate-all Domainname 将不起作用,因为需要完整的包名称。
我倾向于第一次添加 *,然后您将看到其他调用的域类应该是什么样子。

generate-all *

http://grails.org/doc/latest/ref/Command %20Line/generate-all.html

generate-all Domainname will not work as the full package name is needed.
I tent to do add an * for the first time and then you will see what the domain class should look like for the other calls.

generate-all *

http://grails.org/doc/latest/ref/Command%20Line/generate-all.html

写给空气的情书 2024-08-06 14:24:54

它必须是目录名.类名。

如果您创建了一个域类 Book,就像这样 'grails-app/domain/book/Book.groovy'

它应该是: grailsgenerate-app book.Book

It must be dirname.classname.

If you have a domain class created Book, like this 'grails-app/domain/book/Book.groovy'

The it should be: grails generate-app book.Book

听闻余生 2024-08-06 14:24:54

如果您正在使用 Groovy/Grails Tool Suite,则可以通过右键单击您创建的控制器来查看域名,注意域名的确切大小写,然后右键单击视图并生成视图并输入 domainname.viewname

例如,您的控制器名称是 RegistrationController,域名是 helloworld,您可以右键单击视图,然后在生成视图对话框中输入值 helloworld.Registration

If you are working on Groovy/Grails Tool Suite, you can simply see the domain name by right clicking on the controller that you created, notice the exact case for domain name, then right click on views and generate views and type in domainname.viewname

Example, your controller name is RegistrationController and domain name is helloworld, you can right click on views and in generate views dialog, enter the value as helloworld.Registration

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文