Example usage for javax.persistence ValidationMode NONE

List of usage examples for javax.persistence ValidationMode NONE

Introduction

In this page you can find the example usage for javax.persistence ValidationMode NONE.

Prototype

ValidationMode NONE

To view the source code for javax.persistence ValidationMode NONE.

Click Source Link

Document

The persistence provider must not perform lifecycle event validation.

Usage

From source file:org.apache.openjpa.persistence.validation.ValidatorImpl.java

/**
 * Common setup code factored out of the constructors
 *//*from  w  w  w.ja  v  a 2s.c  o  m*/
private void initialize() {
    // only try setting up a validator if mode is not NONE
    if (_mode != ValidationMode.NONE) {
        if (_validatorFactory == null) {
            _validatorFactory = getDefaultValidatorFactory();
        }
        if (_validatorFactory != null) {
            // use our TraversableResolver instead of BV provider one
            _validator = _validatorFactory.usingContext().traversableResolver(new TraversableResolverImpl())
                    .getValidator();
        } else {
            // A default ValidatorFactory could not be created.
            throw new RuntimeException(_loc.get("no-default-factory").getMessage());
        }

        // throw an exception if we have no Validator
        if (_validator == null) {
            // A Validator provider could not be created.
            throw new RuntimeException(_loc.get("no-validator").getMessage());
        }

        if (_conf != null) {
            addValidationGroup(JPAProperties.VALIDATE_PRE_PERSIST, _conf.getValidationGroupPrePersist());
            addValidationGroup(JPAProperties.VALIDATE_PRE_UPDATE, _conf.getValidationGroupPreUpdate());
            addValidationGroup(JPAProperties.VALIDATE_PRE_REMOVE, _conf.getValidationGroupPreRemove());
        } else {
            // add in default validation groups, which can be over-ridden later
            addDefaultValidationGroups();
        }
    } else {
        // A Validator should not be created based on the supplied ValidationMode.
        throw new RuntimeException(_loc.get("no-validation").getMessage());
    }
}