SHARE
TWEET

Untitled

a guest Jul 21st, 2017 219 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.
  2.    
  3. @Documented
  4. @Constraint(validatedBy=PeselValidator.class)
  5. @Target({ElementType.FIELD,ElementType.METHOD,ElementType.ANNOTATION_TYPE})
  6. @Retention(RetentionPolicy.RUNTIME)
  7. public @interface MyPesel {
  8.     String message() default "{wrong.pesel.format}";
  9.  
  10.     Class<?>[] groups() default {};
  11.  
  12.     Class<? extends Payload>[] payload() default {};
  13. }
  14. public class PeselValidator implements ConstraintValidator<MyPesel,String>{
  15.  
  16.     @Override
  17.     public boolean isValid(String arg0, ConstraintValidatorContext arg1) {
  18.         //arg0.matches("^\d{4}[1-31]\d{5}$")
  19.         if(arg0.length()==11)  
  20.             return true;
  21.         else
  22.             return false;
  23.     }
  24.  
  25. }
  26.    
  27. @Entity
  28. public class Author {
  29.     @Id
  30.     @GeneratedValue
  31.     private int Id;
  32.  
  33.     @NotNull
  34.     @Size(min=5,max=30)
  35.     private String name;
  36.  
  37.     @NotNull
  38.     @MyPesel
  39.     private String pesel;
  40.  
  41.     @ManyToMany
  42.     @JoinColumn(name="book_id")
  43.     private Collection<Book> book= new ArrayList<>();
  44.  
  45.     public String getName() {
  46.         return name;
  47.     }
  48.  
  49.     public void setName(String name) {
  50.         this.name = name;
  51.     }
  52.  
  53.     public String getPesel() {
  54.         return pesel;
  55.     }
  56.  
  57.     public void setPesel(String pesel) {
  58.         this.pesel = pesel;
  59.     }
  60. }
  61.    
  62. @Test
  63.     public void goodBookBadAuthor() {
  64.         Book book=new Book();
  65.         book.setTitle("quite good title");
  66.         book.getAuthor().add(new Author());
  67.         Author author=new Author();
  68.         author.setName("y");
  69.         author.setPesel("abc");
  70.         book.getAuthor().add(author);
  71.         Validator validator=validatorFactory.getValidator();
  72.  
  73.         Set<ConstraintViolation<Book>> constraintViolations=validator.validate(book);
  74.  
  75.         assertEquals(2,constraintViolations.size());
  76.     }
  77.    
  78. <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
  79.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  80.     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
  81.              http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
  82.     version="2.1">
  83.  
  84.     <persistence-unit name="ormBook">
  85.         <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
  86.         <class>bean.Book</class>
  87.         <class>bean.Author</class>
  88.         <properties>
  89.             <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />
  90.  
  91.             <property name="javax.persistence.jdbc.url"
  92.                 value="jdbc:mysql://127.0.0.1:3307/db_hibernate_3?useSSL=true&serverTimezone=UTC&logger=Slf4JLogger&profileSQL=true" />
  93.  
  94.             <property name="javax.persistence.jdbc.user" value="root" />
  95.  
  96.             <property name="javax.persistence.jdbc.password" value="jbjb123" />
  97.                   <property name="javax.persistence.validation.mode" value="AUTO"/>
  98.      <property name="javax.persistence.validation.group.pre-persist" value="javax.validation.groups.Default" />
  99.        <property name="javax.persistence.validation.group.pre-update" value="javax.validation.groups.Default" />
  100.        <property name="javax.persistence.validation.group.pre-remove" value=""/>      
  101.             <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
  102.  
  103.  
  104.             <property name="hibernate.connection.isolation" value="2" />
  105.             <property name="hibernate.hbm2ddl.auto" value="create" />
  106.             <property name="hibernate.connection.pool_size" value="10" />
  107.         </properties>
  108.     </persistence-unit>
  109.  
  110. </persistence>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top