I’m trying to avoid persisting some fields in my POJO in to MongoDB.
I tried
1) Adding @javax.persistence.Transient on field.
2) Adding @org.springframework.data.annotation.Transient on field
even i do not use spring at all.
3) Make the field transient
I am using Jakson as the default ObjectMapper of mongodb. and i am not using Spring data to interact with database
But no luck.
The issue is with javax.persistence.Transient But this one, which is a JPA annotation, will not work for MongoDB:
If you want you can use Spring framework @Transient annotation. Spring Documentation
import org.springframework.data.annotation.Transient;
I tried with Spring framework which is working fine for me.
Sample example
@Transient
private Integer age;
If above solution not working the there might be an issue with MappingMongoConverter
Annotation based mapping only works if you're using the MappingMongoConverter (Documentation) as backing converter for MongoTemplate. If you're not configuring the converter a SimpleMongoConverter will be used by default that simply serializes objects into Mongo without taking a look at any meta information whatsoever.