我使用 Morphia 来更新 mongoDB 数据。
我创建了这样的东西:
public UpdateResults<? extends BaseEntity> update(Query<? extends BaseEntity> query,UpdateOperations updateOp) throws WriteConcernException{
return datastore.update(query, updateOp);
}
当我在 eclipse 上运行我的应用程序时,我没有任何问题。
所以当我运行 maven build 时我得到这个错误:
reference to update is ambiguous, both method <T>update(T,org.mongodb.morphia.query.UpdateOperations<T>) in org.mongodb.morphia.Datastore and method <T>update(org.mongodb.morphia.query.Query<T>,org.mongodb.morphia.query.UpdateOperations<T>) in org.mongodb.morphia.Datastore match
我有效地使用了以下方法
<T>update(org.mongodb.morphia.query.Query<T>,org.mongodb.morphia.query.UpdateOperations<T>)
为什么 eclipse 使用正确的方法而 maven 没有?我无法理解。
我如何为 maven 修复它?
最佳答案
作为临时解决方案,您可以使用 datastore.update(query, updateOp, false)
而不是 datastore.update(query, updateOp)
。它会将 createIfMissing 参数作为 false 传递,这已经是默认行为;所以,它不会造成任何问题。
关于java - Morphia更新方式不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27426596/