Yes, here's the code we're using to populate the id field on a new
entity instance:
for (PreCalcRecord pcr : pcrList) {
try {
PreCalcRecord existingRecord =
preCalcDao.getCorrespondingRecord(
pcr.getReferenceUuid(),
pcr.getFirstChoiceUuid(),
pcr.getSecondChoiceUuid());
pcr.setId(existingRecord.getId());
} catch (NoResultException e) {
// No action.
}
this.preCalcDao.save(pcr);
}
And here's the save method:
public final PreCalcRecord save(PreCalcRecord entity) {
if (entity.getId() == null) {
entity.setCreationDate(new Date());
entity.setModifiedDate(new Date());
this.mongoTemplate.save(entity);
} else {
entity.setModifiedDate(new Date());
this.mongoTemplate.save(entity);
}
return entity;
}
On Mar 15, 6:08 am, Scott Hernandez <
scotthernan...@gmail.com> wrote:
> Can you post the code you are using to persist the entity? Are you
> using save(...)?
>
>
>
>
>
>
>
> On Wed, Mar 14, 2012 at 1:29 AM, timfulmer <
tful...@dslextreme.com> wrote:
>
> > Hi All,
>
> > We've been usingMongoto store the results of some analytic types of
> > calculations, and have noticed we occasionally getduplicatedocuments
> > inMongo. Basically we do the calculations in client code, then do a
> > lookup inMongofor a pre-existing document once we've calculated new
> > numbers. If an existing document is found we copy it's id value into
> > the new and pass it into Spring'sMongotemplate. If an existing
> > document is not found we pass the new intoMongotemplate w/o an id
> > attribute.
>
> > Most of the documents we process are not new, we're simply updating
> > existing documents with new numbers. However there are times we get
> >duplicateentries for the documents, one for the old document and one
> > for the new. This happens intermittently, and when it does happen it
> > seems to affect all documents in the collection.
>
> > It could be something Spring is doing;Mongotemplate seems to use
> > upsert under the covers. It may also be something in theMongo
> > driver. We've implemented a workaround to remove duplicates on read,
> > but it seems like strange behavior. Has anyone else encountered
> >duplicateMongodocuments where there should be none?