简体   繁体   中英

java interface on grails domain class

I have four components in my large project that I'm working on...

  1. Existing JPA/Hibernate java library (java domain).
  2. Existing service layer that works with the java domain.
  3. Java class library of only basic interfaces (api and meta-data).
  4. New grails project

I have successfully tied most of this together except one last piece. I have an existing servlet that takes in a interface class from the api but I can't seem to implement my interface on any of the grails domain classes.

An example...

Interface example in the api library...

public interface IPerson{
    public Object getId()
    public String getName()
}

Grails domain class...

class Person implements IPerson{
...
    def getId(){
        return id
    }

    String getName(){
       return name;
    }

}

My project works fine without the interface on the grails domain class but as soon as I add it, it seems to not be identified as an entity . I get errors like

groovy.lang.MissingMethodException: No signature of method: static com.some.thing.Person.getAll() is applicable for argument types: () values: []

Has anyone ever tried something like this?

Problem is apparently caused by the fact that one of the methods is called getId() , so it's essentially defining domain class field id , which clashes with the implicit one. So you can solve the problem by renaming this method or (hopefully, haven't tested myself) changing generation strategy as described here .

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