With the first release of GlassFish 4, the Duke's Tutoring example of the Java EE 7 tutorial issues a constraint violation error when a field that is not annotated @NotNull is specified without a value. We also have a simple test case, validationTest, that I'll try to attach.
The bug occurs when you add a Bean Validation constraint to a field of a JPA entity class, like this:
@Pattern(regexp = "\\(
message = "
private String homePhone;
Note that the field is not required (i.e. it isn't annotated @NotNull).
If you run the validationTest application, go to the following page: http://localhost:8080/validationTest/person/List.xhtml
Create two new instances of Person. In the first, enter a first & last name, and enter a phone number of the form:
You will get a constraint violation, and need to correct it to the form:
Create another instance of Person, entering a first and last name only. This time, leave the HomePhone field blank. What I expected to occur was that the entity would be created. What actually occurs is that you get a constraint violation for HomePhone, even though you didn't enter a value for it, and it isn't a required field.
Why does the constraint violation occur? How do you avoid triggering a constraint violation for empty, non-required fields?
On the Facelets page, the inputText element does not specify the required attribute: