Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data MongoDB prevent persisting certain fields

I am using Spring Data for MongoDB to persist my domain objects. I was wondering if there is a way (perhaps with an Annotation?) to prevent Spring Data from persisting certain fields into MongoDB?

Does someone know how to do that or do I have to write my own Mapper?

Thanks.

like image 597
evermean Avatar asked Mar 04 '13 14:03

evermean


2 Answers

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 Spring Data's MongoDB:

import javax.persistence.Transient;

Which is part of the Java Persistence API.

like image 35
Jeach Avatar answered Oct 03 '22 23:10

Jeach


In this case use the @Transient annotation for the field you need to ignore.

Look more over here - Transient

like image 174
user Avatar answered Oct 03 '22 21:10

user