Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
MongoDB avoid persisting some fields in POJO - Java

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!