bean-validation

Bean Validation Through JPA Relationships

萝らか妹 提交于 2019-12-24 00:12:24
问题 I would like to use Bean Validation to annotate constraints in my entities , now the question is, will the relationships on the entities be validated as well?. For example suppose I have the following entities: @Entity @Table(name = "css_empresa") public class Empresa extends EntidadContactable implements Serializable, Convert { private static final long serialVersionUID = 1L; @Id @SequenceGenerator(name = "EMPRESA_ID_GENERATOR", sequenceName = ConstantesSecuencias.SEQ_EMPRESA)

bean-validation validation.xml ignored

寵の児 提交于 2019-12-23 20:13:29
问题 I am using JSR 303 Bean validation in my JSF 2.0 web application and it works fine with annotations. Now I would like to ignore annotations and configure validation rules using the validation.xml file, so this is what I did (I am using an eclipse dynamic web project) : Added validation.xml under WebContent/META-INF/validation.xml <?xml version="1.0" encoding="UTF-8"?> <validation-config xmlns="http://jboss.org/xml/ns/javax/validation/configuration" xmlns:xsi="http://www.w3.org/2001/XMLSchema

Java bean validation: Enforce a @Pattern only when the property is not blank

做~自己de王妃 提交于 2019-12-23 18:43:07
问题 I have a form that allows the user to optionally enter their zip code. I know how to validate the format of the zip code, by using a @Pattern constraint and regex. But as this is an optional field, I do not want the format validated if it is blank. How can I tell the system to ignore the @Pattern constraint if the field is blank? This is an optional field and I only want to validate it if it is not blank. public class MyForm { String firstName; String lastName; @Pattern(regex = "^\d{5}(?:[-\s

Null Version fields in JPA?

有些话、适合烂在心里 提交于 2019-12-23 18:28:30
问题 Nothing in http://docs.oracle.com/javaee/6/api/javax/persistence/Version.html says it cannot be null. After running import javax.validation.Validation; import javax.validation.Validator; import org.junit.Test; import static org.junit.Assert.assertFalse; public class Test { @Test public void test() { //Using Hibernate Validator 4.1.0.Final... Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); assertFalse(validator.validate(new Foo()).isEmpty()); //why does this

Stop Hibernate from creating not-null constraints

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 12:18:34
问题 Is there a way to stop Hibernate from creating not-null constraints for properties annotated with @javax.validation.constraints.NotNull when using hbm2ddl = create ? 回答1: From the documentation of Hibernate Validator: 6.1. Database schema-level validation Out of the box, Hibernate Annotations (as of Hibernate 3.5.x) will translate the constraints you have defined for your entities into mapping metadata. For example, if a property of your entity is annotated @NotNull , its columns will be

How to solve cast issue java.lang.ClassCastException: $Proxy cannot be cast to NotEmpty wich is annotation

给你一囗甜甜゛ 提交于 2019-12-23 07:55:15
问题 i have REST service project integrated with spring. I am trying to integrate bean validation. i have done a custom annotation: /** * Denotes a field as being no empty. * * @author pguzun */ @Target({METHOD, FIELD, ANNOTATION_TYPE}) @Retention(RUNTIME) @Constraint(validatedBy = {INotEmptyValidator.class}) public @interface NotEmpty { Error error() default Error.ServerError; String message() default "{error.notEmpty}"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default

How to use @Pattern on non-mandatory fields JSR 303

天涯浪子 提交于 2019-12-23 07:06:24
问题 How can i use @Pattern constraint on non-mandatory form fields ? @Pattern(regexp="...") private String something; as soon as i submit my form, i get validation error as expected but the user may leave the field empty, since this is not a mandatory field. PS: i could write my own constraint annotation. However, i just ask an easier way combining annotations or adding annotation attributes. JSR303 implementation is hibernate-validator. 回答1: Just set it with null instead of empty string. Since

How to use @Pattern on non-mandatory fields JSR 303

南笙酒味 提交于 2019-12-23 07:04:05
问题 How can i use @Pattern constraint on non-mandatory form fields ? @Pattern(regexp="...") private String something; as soon as i submit my form, i get validation error as expected but the user may leave the field empty, since this is not a mandatory field. PS: i could write my own constraint annotation. However, i just ask an easier way combining annotations or adding annotation attributes. JSR303 implementation is hibernate-validator. 回答1: Just set it with null instead of empty string. Since

Entity proxy “children” can not be validated even with TraversableResolver

陌路散爱 提交于 2019-12-23 05:23:45
问题 Besides primitive types and String none of the fields of my "Declaration" entity can be validated. They're all ignored by the validator. Issue in Hibernate tracker and Example project. @Entity @Table(name = "declaration") public class Declaration { [fields id, language, ...] @Valid @OneToMany(mappedBy = "declaration", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) @Fetch(value = FetchMode.SUBSELECT) private List<@Valid Child> children = new ArrayList<>(); @Valid

Bean Validation Group inheritance isn't working with Group Sequence Provider

六眼飞鱼酱① 提交于 2019-12-23 05:23:26
问题 I'm currently working on implementing an application that stores contact information which contains both foreign and domestic addresses, but the addresses can also be disabled. I have attempted to define three validation groups: a super group for the always validated info and two child classes for the different address states. public interface ContactValidation {} public interface DomesticValidation extends ContactValidation {} public interface ForeignValidation extends ContactValidation {} I