void buildMapping(Set<Class<?>> classes) throws ClassValidationException {

        long timer = System.currentTimeMillis();

        mappingEngine.clearMapping();
        patternMapping.clear();

        if (classes == null || classes.size() == 0) {
            if (!configuration.getUseClassAutoDescovery()) {
                throw new ClassValidationException(
                        "Configuration.useClassAutoDiscovery is set to false, but no classes were added to configuration");
            }

            logger.log(Level.INFO, "Performing automatic class discovery");
            AnnotationProcessor ap = new AnnotationProcessor();

            for (Class<?> aClass : ap.getClasses("")) {
                configuration.getClasses().add(aClass);
            }
        }

        for (Class<?> aClass : configuration.getClasses()) {

            ClassValidatorUtils.validEntityClass(aClass);

            mappingEngine.createMapping(aClass);
            addPatternMapping(aClass);
        }

        logger.log(Level.INFO, "Configuration finnished, added " + configuration.getClasses().size()
                + " class(es), took " + (System.currentTimeMillis() - timer) + " ms");
    }