I have a fairly simple question about grails domain classes. I am not sure I know how to phrase it correctly since I can’t seem to find the answer on google.
I have a groovy domain class
class DomainObject {
String name
String email
}
and a java class that uses this domain object.
public class DomainUser {
public void method() {
DomainObject object = new DomainObject();
object.getId();
}
}
however I get an error on the line
object.getId();
with the message:
The method getId() is undefined for the type
How do I expose the id to the java class since it is auto generated by the grails application/hibernate?
Id field is generated at run-time and java does not know any thing about dynamic references.
Access that domain from service layer.
http://grails.org/doc/latest/guide/services.html#usingServicesFromJava
also google: “grails access service java”
first result is http://grails.1312388.n4.nabble.com/Question-How-do-I-reference-a-Grails-service-from-within-Java-class-td1462056.html
You can write some thing like this in your DomainService.groovy
Also you must add the id field to your domain class