在尝试使用 Spring-Data MongoDB 将 Object 保存到 mongo DB 时,我遇到了这个异常。
Ambiguous field mapping detected! Both <child class field> and <parent class field> map to the same field name <field name>! Disambiguate using @DocumentField annotation!
我在子类中隐藏了一个字段,这导致了问题。但这对我来说隐藏在父类(super class)中声明的字段是必不可少的。我找不到 @DocumentField 任何地方的注释。我怎样才能在这里继续?还有其他解决方案吗?
最佳答案
对于那些因 Ambiguous field mapping detected!
而来到这里的人(像我一样)与 OP 不太相同的错误,请考虑您的子类甚至可能根本不需要字段,@sparm 提供的答案可以更改为:
public class Parent {
private String myField;
public getMyField() {
return myField;
}
}
@Document(collection = "children")
public class Child extends Parent {
public getMyField() {
super.getMyField();
}
}
关于spring-data - 如何在 spring 数据 mongoDB 中使用 @DocumentField 消除歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26424830/