How can I use grails domain classes (which is in groovy) in service layer which is in Java/Spring.
When using the grails MVC, everything is fine as I can use contro
Where as InvokerHelper
works well, if you have access to the GORM class I would put wrapper functions around the GORM calls -- then the Java classes will see that.
static String List getAll() { return User.list() }
static String User getByID(long id) { return User.get(id) }
That seems cleaner and doesn't put a dependency on a Groovy class in your Java code.
Sample Code Snippet :
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);
org.codehaus.groovy.runtime.InvokerHelper makes this pretty straightforward; see this mailing list thread: http://grails.1312388.n4.nabble.com/Calling-Dynamic-Finders-on-Domain-Class-via-the-MetaClass-td1596496.html