8

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.

2 Answers 2

15

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

Look more over here - Transient

Sign up to request clarification or add additional context in comments.

Comments

5

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.