Last active
February 1, 2017 05:17
-
-
Save thjanssen/8067d07da527bb79602e0c2b81f336eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class Book implements Serializable { | |
@Column | |
@NotNull | |
@Size(min=5, max=20) | |
private String title; | |
… | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>javax.el</groupId> | |
<artifactId>javax.el-api</artifactId> | |
<version>2.2.4</version> | |
</dependency> | |
<dependency> | |
<groupId>org.glassfish.web</groupId> | |
<artifactId>javax.el</artifactId> | |
<version>2.2.4</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18:21:33,229 ERROR ExceptionMapperStandardImpl:39 – HHH000346: Error during managed flush [Validation failed for classes [org.thoughts.on.java.model.Book] during persist time for groups [javax.validation.groups.Default, ] | |
List of constraint violations:[ConstraintViolationImpl{interpolatedMessage=’may not be null’, propertyPath=title, rootBeanClass=class org.thoughts.on.java.model.Book, messageTemplate='{javax.validation.constraints.NotNull.message}’}]] | |
18:21:33,233 INFO TestAttributeValidation:50 – ConstraintViolationImpl{interpolatedMessage=’may not be null’, propertyPath=title, rootBeanClass=class org.thoughts.on.java.model.Book, messageTemplate='{javax.validation.constraints.NotNull.message}’} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18:59:40,241 ERROR ExceptionMapperStandardImpl:39 – HHH000346: Error during managed flush [Validation failed for classes [org.thoughts.on.java.model.Book] during update time for groups [javax.validation.groups.Default, ] | |
List of constraint violations:[ConstraintViolationImpl{interpolatedMessage=’size must be between 5 and 20′, propertyPath=title, rootBeanClass=class org.thoughts.on.java.model.Book, messageTemplate='{javax.validation.constraints.Size.message}’}]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-validator</artifactId> | |
<version>5.3.4.Final</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityManager em = emf.createEntityManager(); | |
em.getTransaction().begin(); | |
Book b = new Book(); | |
em.persist(b); | |
try { | |
em.getTransaction().commit(); | |
Assert.fail(“ConstraintViolationException exptected”); | |
} catch (RollbackException e) { | |
Set<ConstraintViolation<?>> violations = ((ConstraintViolationException)e.getCause()).getConstraintViolations(); | |
for (ConstraintViolation v : violations) { | |
log.info(v); | |
} | |
} | |
em.close(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityManager em = emf.createEntityManager(); | |
em.getTransaction().begin(); | |
Book b = em.find(Book.class, 1000L); | |
b.setTitle(“This is a very long title with more than 20 characters.”); | |
try { | |
em.getTransaction().commit(); | |
Assert.fail(“ConstraintViolationException exptected”); | |
} catch (RollbackException e) { | |
log.error(e); | |
} | |
em.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment