private boolean doValidate(PersistentEntity entity, Object o) { Validator v = datastore.getMappingContext().getEntityValidator(entity); if (v == null) { return true; } Session currentSession = datastore.getCurrentSession(); FlushModeType flushMode = currentSession.getFlushMode(); try { currentSession.setFlushMode(FlushModeType.COMMIT); Errors result = new ValidationErrors(o); v.validate(o, result); if (result.hasErrors()) { onErrors(o, result); return false; } return true; } finally { currentSession.setFlushMode(flushMode); } }