1 package de.juplo.plugins.hibernate4;
3 import javax.validation.Validation;
5 import org.hibernate.cfg.Configuration;
6 import org.hibernate.cfg.beanvalidation.TypeSafeActivatorAccessor;
7 import org.hibernate.dialect.Dialect;
8 import org.hibernate.metamodel.source.MappingException;
12 * This integration is usually performed by BeanValidationIntegrator.
13 * Unfortunately, that integration will only be activated upon
14 * initialization of the ServiceRegistry, which initializes
15 * DatasourceConnectionProviderImpl, which looks up the datasource,
16 * which requires a JNDI context ...
17 * We therefore reimplement the relevant parts of BeanValidatorIntegrator.
18 * Since that must occur after secondPassCompile(), which is invoked by
19 * Configuration.generateSchemaCreationScript, which is invoked by
20 * SchemaExport, some fancy subclassing is needed to invoke the integration
22 * @author Mark Robinson <mark@mrobinson.ca>
23 * @author Frank Schimmel <frank.schimmel@cm4all.com>
25 public class ValidationConfiguration extends Configuration
27 private static final long serialVersionUID = 1L;
31 protected void secondPassCompile() throws MappingException
33 super.secondPassCompile();
37 TypeSafeActivatorAccessor.applyRelationalConstraints(
38 Validation.buildDefaultValidatorFactory(),
41 ((Class<Dialect>)Class.forName(getProperty(Hbm2DdlMojo.DIALECT))).newInstance()
46 throw new RuntimeException(e);
50 public String getTypeDefs()
52 return typeDefs.entrySet().toString();