<!-- Zeichensatz -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Verwendete Versionen -->
- <hibernate-core.version>4.3.0.Final</hibernate-core.version>
- <hibernate-envers.version>4.3.0.Final</hibernate-envers.version>
+ <hibernate-core.version>4.3.1.Final</hibernate-core.version>
+ <hibernate-envers.version>4.3.1.Final</hibernate-envers.version>
+ <hibernate-validator.version>4.3.1.Final</hibernate-validator.version>
<maven.version>3.0.4</maven.version>
<maven-plugin-log4j.version>1.0.1</maven-plugin-log4j.version>
<scannotation.version>1.0.3</scannotation.version>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
- <version>4.3.1.Final</version>
+ <version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>org.scannotation</groupId>
throw new MojoFailureException("Hibernate configuration is missing!");
}
- Configuration config= null;
- try
- {
- config = new ValidationConfiguration(hibernateDialect);
- }
- catch (ClassNotFoundException e)
- {
- e.printStackTrace();
- }
+ final Configuration config = new ValidationConfiguration(hibernateDialect);
config.setProperties(properties);
package de.juplo.plugins.hibernate4;
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Properties;
+import javax.validation.Validation;
+
import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.beanvalidation.TypeSafeActivatorAccessor;
import org.hibernate.dialect.Dialect;
import org.hibernate.metamodel.source.MappingException;
* SchemaExport, some fancy subclassing is needed to invoke the integration
* at the right time.
* @author Mark Robinson <mark@mrobinson.ca>
+ * @author Frank Schimmel <frank.schimmel@cm4all.com>
*/
public class ValidationConfiguration extends Configuration
{
- Class dialectClass;
+ private static final long serialVersionUID = 1L;
+
+ private Class<Dialect> dialectClass;
- public ValidationConfiguration(String dialectClass)
- throws
- ClassNotFoundException
+ public ValidationConfiguration(final String dialectClass)
{
- this.dialectClass = Class.forName(dialectClass);
+ try {
+ this.dialectClass = (Class<Dialect>) Class.forName(dialectClass);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
}
@Override
try
{
- /** Thank you, hibernate folks, for making this useful class package private ... */
- Method applyDDL =
- Class
- .forName("org.hibernate.cfg.beanvalidation.TypeSafeActivator")
- .getMethod(
- "applyRelationalConstraints",
- Collection.class,
- Properties.class,
- Dialect.class
- );
- applyDDL.setAccessible(true);
- applyDDL.invoke(
- null,
+ TypeSafeActivatorAccessor.applyRelationalConstraints(
+ Validation.buildDefaultValidatorFactory(),
classes.values(),
getProperties(),
dialectClass.newInstance()
--- /dev/null
+package org.hibernate.cfg.beanvalidation;
+
+/**
+ * This class enables access to the public methods of {@link TypeSafeActivator}
+ * which itself is visible in the package only.
+ *
+ * @author Frank Schimmel <frank.schimmel@cm4all.com>
+ */
+public class TypeSafeActivatorAccessor extends TypeSafeActivator {
+ // Empty: just makes public methods accessible.
+}