protected function validate(LifecycleEventArgs $args) {
        $entity = $args->getEntity();
        $metadata = $args->getEntityManager()->getClassMetadata(get_class($entity));
        if($this->shouldBeValidated($entity)) {
            $rules = $entity->getValidationRules();
            $fields = $metadata->getFieldNames();
            $data = [];
            foreach($fields as $field) {
                $data[$field] = $metadata->getFieldValue($entity, $field);
            }

            $this->validator->with($data, $rules);
            if(!$this->validator->passes()) {
                throw new InvalidEntityException($entity, $this->validator->errors());
            }
        }
    }