views:

1920

answers:

8

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
+1  A: 

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?

duffymo
I did it from the NetBeans IDE. I tink the problem was that when I created the file I selected the option "create a groovy class" instead of the option "create a domain class".I guess somewhere in some secret config file is a list of classes that are Domains and that the create-domain-class does the necessary housekeeping.
ראובן
Yes, create-domain-class is the key.
duffymo
The Groovy file simply has to be in the grails-app/domain folder. There is no secret config file
Scott Warren
+2  A: 

Run:

grails clean

and then re-run the generate-all command.

ref: http://parasjain.net/2009/06/23/grails-no-domain-class-found-for-name-please-try-again-and-enter-a-valid-domain-class-name/

Tim Abell
+1  A: 

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

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

Tim Abell
+1  A: 

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

Tim Abell
A: 

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"

cczhu
A: 

grails generate-all projectname.Class

worked for me. Thank Tim!

abcdef123
A: 

"grails generate-all helloworld.User" This worked!!!thanks

jvandal