简体   繁体   English

java 接口 grails 域 class

[英]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).现有的 JPA/Hibernate java 库(java 域)。
  2. Existing service layer that works with the java domain.与 java 域一起使用的现有服务层。
  3. Java class library of only basic interfaces (api and meta-data). Java class 仅包含基本接口(api 和元数据)的库。
  4. New grails project新grails项目

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.我有一个现有的 servlet,它接收来自 api 的接口 class 但我似乎无法在任何 grails 域类上实现我的接口。

An example...一个例子...

Interface example in the api library... api 库中的接口示例...

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

Grails domain class... Grails 域 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 .我的项目在没有 grails 域 class 上的接口的情况下工作正常,但是一旦我添加它,它似乎就没有被识别为实体 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.问题显然是由于其中一种方法称为getId() ,因此它本质上是定义域 class 字段id ,这与隐式方法冲突。 So you can solve the problem by renaming this method or (hopefully, haven't tested myself) changing generation strategy as described here .因此,您可以通过重命名此方法或(希望自己尚未测试过)更改生成策略来解决问题,如此所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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