Spring Data MongoDB and JSR Validation using Lazy DBRef
The Problem Recently using MongoDB and Spring Data I encountered an interesting issue. Saving an Entity which was loaded by @DBRef(lazy = true) wasn’t possible together with the activated ValidatingMongoEventListener. Each time the following error occurred: javax.validation.ConstraintViolationException at org.springframework.data.mongodb.core.mapping.event.ValidatingMongoEventListener.onBeforeSave(ValidatingMongoEventListener.java:65) at org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener.onBeforeSave(AbstractMongoEventListener.java:144) at org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener.onApplicationEvent(AbstractMongoEventListener.java:90) at org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener.onApplicationEvent(AbstractMongoEventListener.java:33) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:381) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:335) at org.springframework.data.mongodb.core.MongoTemplate.maybeEmitEvent(MongoTemplate.java:1633) at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:986) at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:933)…