Skip to content

Commit

Permalink
DATAMONGO-617 - Fixed potential NullPointerException in MongoTemplate…
Browse files Browse the repository at this point in the history
….insert(…).

If MongoTemplate.insert(…) was called with a Mongo-simple type (such as a raw DBBobject) it caused a NullPointerException during the lookup of a version property. This is now fixed by correcting the guard.
  • Loading branch information
odrotbohm committed Feb 20, 2013
1 parent bf81d95 commit f337900
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -666,7 +666,7 @@ private void initializeVersionProperty(Object entity) {

MongoPersistentEntity<?> mongoPersistentEntity = getPersistentEntity(entity.getClass());

if (mongoPersistentEntity == null || mongoPersistentEntity.hasVersionProperty()) {
if (mongoPersistentEntity != null && mongoPersistentEntity.hasVersionProperty()) {
BeanWrapper<PersistentEntity<Object, ?>, Object> wrapper = BeanWrapper.create(entity, null);
wrapper.setProperty(mongoPersistentEntity.getVersionProperty(), 0);
}
Expand Down
Expand Up @@ -1318,6 +1318,18 @@ public void optimisticLockingHandlingWithExistingId() {
template.save(person);
}

/**
* @see DATAMONGO-617
*/
@Test
public void doesNotFailOnVersionInitForUnversionedEntity() {

DBObject dbObject = new BasicDBObject();
dbObject.put("firstName", "Oliver");

template.insert(dbObject, template.determineCollectionName(PersonWithVersionPropertyOfTypeInteger.class));
}

/**
* @see DATAMONGO-539
*/
Expand Down

0 comments on commit f337900

Please sign in to comment.