Mongo - Ignore property from being persisted

↘锁芯ラ 提交于 2019-11-28 02:23:36

问题


I have a standard POJO that has a set of properties in it. The POJO has been annotated as a @Document, so as to be persisted in MongoDB as a Document.

How (annotation??) can I ignore/avoid one of the properties in the POJO from being persisted?


回答1:


The @Transient annotation it is. See http://static.springsource.org/spring-data/data-document/docs/current/reference/html/#mapping-usage-annotations




回答2:


In case you are looking for the actual package like I was, this one will work:

import org.springframework.data.annotation.Transient;

Which is from the Spring framework API documentation.

But this one, which is a JPA annotation, will not work for MongoDB:

import javax.persistence.Transient;

Which is part of the Java Persistence API.




回答3:


use @Transient be aware that you use the below package

import org.springframework.data.annotation.Transient;


来源:https://stackoverflow.com/questions/8254856/mongo-ignore-property-from-being-persisted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!