我用 @ReadOnlyProperty 注释了实体 pojo 中的一些键,因为我不想从工作应用程序中设置这些字段,因为这些字段将从不同的应用程序中设置/更新。
@Document
public class SimpleClass{
@Id
@Field(targetType = FieldType.OBJECT_ID)
private String id;
// this key will be updated from current application
private String key1;
/// below key will be created/updated from different flow
/// I don't want to create/update this data from current application
/// I want this key for read purpose only
@ReadOnlyProperty
private String key2;
//SETTERS - GETTERS Ommited
}
我从 pojo 创建了 mongo 存储库。
public interface SimpleClassRepository extends MongoRepository<SimpleClass, String>{
}
我正在尝试通过 simpleClassRepository.save() 方法更新已读取的文档。 数据库文档正在更新其他字段,但这些 @ReadOnlyProperty 键已从文档中删除。 我正在使用 spring data mongodb 3.4.1。 谁能建议如何解决这个问题
我尝试也在实体中添加@Version,但结果仍然相同。