1 package de.juplo.plugins.hibernate4;
2
3 import javax.validation.Validation;
4
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;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public class ValidationConfiguration extends Configuration
26 {
27 private static final long serialVersionUID = 1L;
28
29 private Class<Dialect> dialectClass;
30
31 public ValidationConfiguration(final String dialectClass)
32 {
33 try {
34 this.dialectClass = (Class<Dialect>) Class.forName(dialectClass);
35 } catch (ClassNotFoundException e) {
36 throw new RuntimeException(e);
37 }
38 }
39
40 @Override
41 protected void secondPassCompile() throws MappingException
42 {
43 super.secondPassCompile();
44
45 try
46 {
47 TypeSafeActivatorAccessor.applyRelationalConstraints(
48 Validation.buildDefaultValidatorFactory(),
49 classes.values(),
50 getProperties(),
51 dialectClass.newInstance()
52 );
53 }
54 catch (Exception e)
55 {
56 throw new RuntimeException(e);
57 }
58 }
59
60 public String getTypeDefs()
61 {
62 return typeDefs.entrySet().toString();
63 }
64 }