List of usage examples for org.springframework.data.mongodb.core.mapping MongoSimpleTypes AUTOGENERATED_ID_TYPES
Set AUTOGENERATED_ID_TYPES
To view the source code for org.springframework.data.mongodb.core.mapping MongoSimpleTypes AUTOGENERATED_ID_TYPES.
Click Source Link
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
private void assertUpdateableIdIfNotSet(Object entity) { MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entity.getClass()); MongoPersistentProperty idProperty = persistentEntity.getIdProperty(); if (idProperty == null) { return;/* ww w .j ava 2 s .co m*/ } ConversionService service = mongoConverter.getConversionService(); Object idValue = BeanWrapper.create(entity, service).getProperty(idProperty, Object.class, true); if (idValue == null && !MongoSimpleTypes.AUTOGENERATED_ID_TYPES.contains(idProperty.getType())) { throw new InvalidDataAccessApiUsageException( String.format("Cannot autogenerate id of type %s for entity of type %s!", idProperty.getType().getName(), entity.getClass().getName())); } }