56

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?

Saket
  • 45,521
  • 12
  • 59
  • 79

3 Answers3

95

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

Jason Law
  • 965
  • 1
  • 9
  • 21
Saket
  • 45,521
  • 12
  • 59
  • 79
53

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.

Jeach
  • 8,656
  • 7
  • 45
  • 58
3

use @Transient be aware that you use the below package

import org.springframework.data.annotation.Transient;
Pravin Bansal
  • 4,315
  • 1
  • 28
  • 19