bean-validation

JSR-303 and JPA overlapping

好久不见. 提交于 2020-01-01 06:38:13
问题 Aloha hey! I already use JPA annotations, now I'd like to use JSR-303 annotations to validate attributes as well. My questions is, how well do they interact with each other? If I use @Basic(optional=false) or @NotNull , will I still have to use nullable=false etc.? I haven't decided which validator implementation to use, e.g. hibernate-validator or oVal (You may also suggest others. I know that oVal is not a JSR-303 implementation, but it maps most annotations). oVal manual (see above) states

How to set Locale in Bean Validation

…衆ロ難τιáo~ 提交于 2020-01-01 06:15:29
问题 By default Bean Validation gets Locale based on Locale.getDefault(), which is common to whole JVM. How to change BeanValidation's Locale for current EJB method call? I'm using JavaEE7 and want to get benefits from integration of JPA and Bean Validation, i.e. automatic triggering validation on insert/update/delete events, and as far as possible avoid of writing everything manually. EDIT After all, I'm just returning non-interpolated messages from EJB: public class DoNothingMessageInterpolator

How to set Locale in Bean Validation

亡梦爱人 提交于 2020-01-01 06:15:26
问题 By default Bean Validation gets Locale based on Locale.getDefault(), which is common to whole JVM. How to change BeanValidation's Locale for current EJB method call? I'm using JavaEE7 and want to get benefits from integration of JPA and Bean Validation, i.e. automatic triggering validation on insert/update/delete events, and as far as possible avoid of writing everything manually. EDIT After all, I'm just returning non-interpolated messages from EJB: public class DoNothingMessageInterpolator

Kotlin data class and bean validation with container element constraints

南楼画角 提交于 2019-12-31 21:11:07
问题 With Bean Validation 2.0 it is possible to also put constraints on container elements. I cannot get this to work with Kotlin data classes: data class Some(val someMap: Map<String, @Length(max = 255) String>) This does not have any effect. Any ideas? I created a repository with a sample project to reproduce the case: https://github.com/mduesterhoeft/bean-validation-container-constraints 来源: https://stackoverflow.com/questions/51085138/kotlin-data-class-and-bean-validation-with-container

Kotlin data class and bean validation with container element constraints

左心房为你撑大大i 提交于 2019-12-31 21:10:54
问题 With Bean Validation 2.0 it is possible to also put constraints on container elements. I cannot get this to work with Kotlin data classes: data class Some(val someMap: Map<String, @Length(max = 255) String>) This does not have any effect. Any ideas? I created a repository with a sample project to reproduce the case: https://github.com/mduesterhoeft/bean-validation-container-constraints 来源: https://stackoverflow.com/questions/51085138/kotlin-data-class-and-bean-validation-with-container

How to autowire service in ConstraintValidator

此生再无相见时 提交于 2019-12-31 00:01:09
问题 I'm writting my application using Spring MVC. I want to validate is e-mail exists in database when user is registering. I've written my own annotation constraint named UniqueEmail . My User entity User.java : @Entity @Table(name="users") public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Column(name = "email", length = 100, nullable = false, unique = true) @NotEmpty @Email @UniqueEmail(message = "E-mail is not unique") private String email; @Column

Java Bean Validation: How do I specify multiple validation constraints of the same type but with different groups?

你离开我真会死。 提交于 2019-12-30 17:35:31
问题 I have multiple processes in which the bean properties must have different values. Example: @Min( value=0, groups=ProcessA.class ) @Min( value=20, groups=ProcessB.class ) private int temperature; Unfortunately the bean validation JSR 303 has not set @Repeatable on javax.validation.constraints.Min so this approach does not work. I found "Min.List" but without any doc about how to use it. Instead the official Oracle doc states at http://docs.oracle.com/javaee/7/api/javax/validation/constraints

Using Hibernate Validator with JPA and Spring

孤街醉人 提交于 2019-12-30 11:00:11
问题 I'm using Hibernate Validator 4.0.2, Spring 3.0 and Hibernate 3.3.2 (which, as I understand it, is pre-JPA2) as a JPA 1 provider. I've found it easy to integrate the Validator into the MVC layer (it just works) but can't see how to integrate the validator automatically into the JPA entityManager (JPA 1). Basically, I have some entities that will be persisted but that do not come from the web layer and have therefore not already been validated. I'd like a neat way of running them through the

Hibernate validations on save (insert) only

北战南征 提交于 2019-12-29 08:46:08
问题 We encountered a problem with legacy code. There is a validation set for a "username" field, validating its length and making sure it contains at least one letter: @Column(name = "username") @Size(min = 4, max = 40) @Pattern(regexp = "^.*[a-zA-Z]+.*$") private String username; The problem we have is that some existing legacy data do not fit these validations, and I'm trying to find a way to make these validations to be ignored for legacy data (old users), while still be applied to newly

Validate elements of a String array with Java Bean Validation

两盒软妹~` 提交于 2019-12-29 08:44:09
问题 I have a simple class that has one of its properties as a String array. As per this document, using @Valid on an array, collection etc. will recursively validate each element of the array/collection. @Valid @Pattern(regexp="^[_ A-Za-z0-9]+$") public String[] defaultAppAdminRoles; the above annotation on the property generates the following exception: Exception in thread "main" javax.validation.UnexpectedTypeException: No validator could be found for type java.lang.String[]. See: @Pattern at