简体   繁体   中英

Grails domain class method from java source error: cannot find symbol

In my app I have a grails domain class Student. I also have a few classes in src.java originally written in plain java.

In one of those classes in some method I am trying to get a collection of students like this:

this.students = new ArrayList<Student>(Student.findAll());

Grails package is imported, intellij doesn't complain, however I get foolwing error while trying to compile.

[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
  [groovyc] Compile error during compilation with javac.
  [groovyc] F:\path\ProjectName\src\java\grb\StudentSchedule.java:58: error: cannot find symbol
  [groovyc]         this.students = new ArrayList<Student>(Student.findAll());
  [groovyc]                                                       ^
  [groovyc]   symbol:   method findAll()
  [groovyc]   location: class Student

I have been also trying different methods, on Student, but all give me the same error - cannot find symbol.

As the Grails docs state: You can also write Grails domain classes in Java
You have to use org.codehaus.groovy.runtime.InvokerHelper from Java
For more information see this mailing list
Kind of sample code :

import my.package.User
import org.codehaus.groovy.runtime.InvokerHelper;

List allInstances = (List)InvokerHelper.invokeMethod(User.class, "list", null)); 

User one=(User)InvokerHelper.invokeMethod(User.class, "get", id);

maybe this post can help as well.
But I would agree on the idea of writing the classes in Groovy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM