bean-validation

Hibernate not following JPA specifications when combined with Bean Validation API?

寵の児 提交于 2019-12-01 03:15:52
This question is a follow up to this one : JPA ConstraintViolation vs Rollback I did some test about combination of JPA and validation API (JSR-303). I found the following in JPA specifications (page 101-102): By default, the default Bean Validation group (the group Default) will be validated upon the pre-persist and pre-update lifecycle validation events ... If the set of ConstraintViolation objects returned by the validate method is not empty, the persistence provider must throw the javax.validation.ConstraintViolationException containing a reference to the returned set of

Customizing JAX-RS response when a ConstraintViolationException is thrown by Bean Validation

隐身守侯 提交于 2019-12-01 02:52:41
问题 Bean Validation is a good option to validate objects, but how to customize the response of a REST API (using RESTeasy) when a ConstraintViolationException is thrown? For example: @POST @Path("company") @Consumes("application/json") public void saveCompany(@Valid Company company) { ... } A request with invalid data will return a HTTP 400 status code with the following body: [PARAMETER] [saveCompany.arg0.name] [{company.name.size}] [a] It's nice but not enough, I would like to normalize these

Jersey/JAX-RS resource method input bean validation

半世苍凉 提交于 2019-12-01 02:52:40
问题 I am using Jersey/JAX-RS via DropWizard 0.7.1 to expose RESTful service endpoints. I have all of my entity POJOs annotated with both JAX-RS and Hibernate/JSR-303 bean validation annotations like so: public class Widget { @JsonProperty("fizz") @NotNull @NotEmpty private String fizz; // Can't be empty or null @JsonProperty("buzz") @Min(value=5L) private Long buzz; // Can't be less than 5 // etc. } When a resource method receives one of these POJOs as input (under the hood, DropWizard has

Bean Validation with JAX-RS (rest-easy): parameter name not recognized

Deadly 提交于 2019-12-01 02:41:12
问题 I'm using JAX-RS resources with Bean Validation and integration between these two works as expected. However, the default error messages generated in case of a validation error report parameter names as arg0, like so [PARAMETER] [login.arg0.password] [password is required] [] Corresponding method definition: @POST //and other JAX-RS annotations public Response login( @NotNull @Valid LoginBody loginBody) { [...] protected static class LoginBody { @NotNull(message = EMAIL_REQUIRED) public

How to validate field level constraint before class level constraint?

偶尔善良 提交于 2019-12-01 00:45:19
I have a class: @ColumnNameUnique(groups = CreateTableChecks.class) public class Table { @Valid @NotEmpty(groups = CreateTableChecks.class) private List<Measure> measures; } The class level constraint @ColumnNameUnique(groups = CreateTableChecks.class) always runs first, after that the field level constraint @NotEmpty(groups = CreateTableChecks.class) runs. Is there anyway to force the the field level constraint @NotEmpty(groups = CreateTableChecks.class) runs first? You need to use @GroupSequence and re-define the default group sequence . Without this the validation order within a group is

JSF 2.0: h:inputText inside composite component fails with non-String objects when validation is set

∥☆過路亽.° 提交于 2019-12-01 00:39:20
In a backing bean: @Min(3) Integer foo; If I have form like: <h:form> <h:commandButton value="Submit" /> <h:inputText value="#{bean.foo}" /> </h:form> This works ok. However, if I do something like <cc:interface> <cc:attribute name="text" /> <cc:editableValueHolder name="text" targets="field" /> <cc:interface> <cc:implementation> <h:inputText id="field" value="#{cc.attrs.text}" /> </cc:implementation> and call this inside form instead of directly h:inputText as in: <!-- <h:inputText value="#{bean.foo}" /> --> <pref:fieldComponent text="#{bean.foo}" /> But then I get: javax.validation

JSR303 Composite Annotation

老子叫甜甜 提交于 2019-12-01 00:24:49
I've created a composite annotation that consists of @Digits and @Min @Digits(integer=12, fraction=0) @Min(value=0) @ReportAsSingleViolation @Documented @Retention(RetentionPolicy.RUNTIME) @Target( { FIELD, METHOD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) @Constraint(validatedBy={}) public @interface PositiveInt { String message() default "{positive.int.msg}"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; } my problem is, I want to reuse this annotation where I want the @Digits 'integer' value to be specify when the PositiveInteger is use example public

Does scala suport JSR-303 validation?

我与影子孤独终老i 提交于 2019-11-30 23:44:47
Does scala supports JSR-303 validation? If it does - could you please write an example? If it does not - are there workarounds to run JSR-303 validation on scala classes? There is good news and bad news. The good news is that you can use JSR-303 annotations in your Scala code with no problems. Here is an example from a previous project of mine, where all of the annotations are JSR-303 annotations, some of them out of the box, some of them custom. @MessagesValid class Messages { @NotEmpty @Valid private var msgs: java.util.List[DeliveredMessage] = _ def messages = msgs.asScala @ChannelValid var

Hibernate not following JPA specifications when combined with Bean Validation API?

你离开我真会死。 提交于 2019-11-30 23:27:31
问题 This question is a follow up to this one : JPA ConstraintViolation vs Rollback I did some test about combination of JPA and validation API (JSR-303). I found the following in JPA specifications (page 101-102): By default, the default Bean Validation group (the group Default) will be validated upon the pre-persist and pre-update lifecycle validation events ... If the set of ConstraintViolation objects returned by the validate method is not empty, the persistence provider must throw the javax

JSR-303 validation groups define a default group

独自空忆成欢 提交于 2019-11-30 22:27:20
问题 I have a bean that has a lot of fields annotated with JSR-303 validation annotations. There is a new requirement now that one of the fields is mandatory, but only in certain conditions. I looked around and have found what I needed, validation groups. This is what I have now: public interface ValidatedOnCreationOnly { } @NotNull(groups = ValidatedOnCreationOnly.class) private String employerId; @Length(max = 255) @NotNull private String firstName; @Length(max = 255) @NotNull private String