I am persisting a object:
@Document
public class PotentialCandidates {
@Id
private String jobid;
@CreatedDate
private DateTime created;
@LastModifiedDate
private DateTime modified;
private DBObject potentialcandidates;
public String getJobid() {
return this.jobid;
}
public void setJobid(String jobid) {
this.jobid = jobid;
}
public DBObject getPotentialcandidates() {
return this.potentialcandidates;
}
public void setPotentialcandidates(DBObject potentialcandidates) {
this.potentialcandidates = potentialcandidates;
}
}
where potentialCandidates
are set from a JSON string as so:
potentialCandidatesObj.setPotentialcandidates((DBObject)JSON.parse(valStr));
This persists fine to my mongodb and gives me an object on the DB I can drill down into, however when I try to retrieve my db object:
public PotentialCandidates getPotentialCandidatesByJobid(String jobid) throws NoSuchPotentialCandidatesException , SystemException{
PotentialCandidates Jobid = null;
try {
Query query = new Query();
query.addCriteria(Criteria.where("_id").is(jobid));
Jobid = mongoTemplateJobs.findOne(query, PotentialCandidates.class,
COLLECTION_NAME);
return Jobid;
} catch (Exception ex) {
throw new SystemException(ex);
} finally {
if (Jobid == null) {
throw new NoSuchPotentialCandidatesException("No User with jobid: "
+ jobid + "found..");
}
}
}
I encounter the following error:
org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.util.ArrayList<?> to type com.mongodb.DBObject for value 'myString'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.util.LinkedHashMap<?, ?> to type com.mongodb.DBObject
So it would seem I need some sort of logic to handle retrieves from mongo. I could use a different return class in my findOne
query but that seems a little messy. Is there a standard approach to dealing with this?