Questions tagged [bean-validation]

Bean Validation, previously commonly called just "JSR-303", is an annotation based validation framework for javabean properties and parameters of arbitrary methods. Hibernate Validator is the reference implementation and the most widely used one.

Online resources

1913 questions
7
votes
3 answers

@NotNull on subclass getter affects parent class table

I have a question related to javax.validation.constraints.NotNull annotation. In my project i do have classes tree like following : @Inheritance(strategy = InheritanceType.JOINED) class Ssss { @ManyToOne private Xxxx x; public Xxxx…
Michal W
  • 318
  • 4
  • 11
7
votes
4 answers

Bean Validation range constraint

I need to implement range constraints on Entity data fields: @Entity @Table(name = "T_PAYMENT") public class Payment extends AbstractEntity { //.... //Something like that @Range(minValue = 80, maxValue = 85) private Long…
J-Alex
  • 6,881
  • 10
  • 46
  • 64
7
votes
1 answer

Validating Integer using JSR303

I decided to use JSR303 to validate my forms in Spring 3.0 MVC application. When I try to check @NotEmpty on Integer variable I have exception: javax.validation.UnexpectedTypeException: No validator could be found for type:…
Marek
  • 457
  • 8
  • 17
7
votes
1 answer

How can I apply a @NotNull constraint to all fields in a class using javax.validation?

I'm using the hibernate implementation of the javax.validation and would like to know how whether anyone has been able to apply the @NotNull constraint annotation to all fields of a class, rather than to each individual field? I would prefer to…
Paco
  • 73
  • 1
  • 3
7
votes
1 answer

How to override @annotations (javax.validation) in a subClass

I have this Entity, that is a super class: @Entity public class Father implements Serializable{ @Column(name = "name") @Size(min=1, max=10) @Pattern(regexp="^[A-Za-z ]*$") @NotNull private String name; } this one, extends…
MDP
  • 4,177
  • 21
  • 63
  • 119
7
votes
1 answer

How can I define one Java annotation in terms of another?

For example, I'd like to have @Nonnegative, defined as @Min(0), and @DaySeconds, defined as @Min(0) @Max(86399).
Reuben Thomas
  • 647
  • 6
  • 13
7
votes
2 answers

Custom class level bean validation constraint

I already know how to add annotation based validation on specific attributes in Entity class like :- public class Person { @NotNull private String firstName; private String lastName; //... } But is it possible to add annotation…
AnkeyNigam
  • 2,810
  • 4
  • 15
  • 23
7
votes
3 answers

Validate elements of a String array with Java Bean Validation

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…
Ironluca
  • 3,402
  • 4
  • 25
  • 32
7
votes
2 answers

Purpose of @NotNull.List

When I looked among the standard constraints in Bean Validation API (JSR-303), I found the NotNull.List annotation. Its description is: Defines several @NotNull annotations on the same element This is valid syntax: @NotNull.List({@NotNull,…
holmis83
  • 15,922
  • 5
  • 82
  • 83
7
votes
3 answers

java/beans validation - collection/map does not contain nulls

There is the @NotNull annotation which validates that a certain object is not null. There is the @NotEmpty annotation which validates that a certain collection/map/string/... is not empty. Is there also an annotation which valides that a certain…
user4460845
7
votes
2 answers

Adding constraint violation manually

Is it possible to add constraint violation manually? E.g.: // validate customer (using validation annotations) Set> violations = validator.validate(customer); if (someSpecialCase) { violations.add(..) } The…
Marcel Overdijk
  • 11,041
  • 17
  • 71
  • 110
7
votes
3 answers

How to autowire service in ConstraintValidator

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…
Mufanu
  • 534
  • 7
  • 18
7
votes
3 answers

Hibernate Validator and Jackson: Using the @JsonProperty value as the ConstraintViolation PropertyPath?

Say I have a simple POJO like below annotated with Jackson 2.1 and Hibernate Validator 4.3.1 annotations: final public class Person { @JsonProperty("nm") @NotNull final public String name; public Person(String name) { this.name =…
Philip Lombardi
  • 1,276
  • 2
  • 17
  • 26
7
votes
1 answer

Binding JAX-RS bean validation error messages to the view

We can easily validate a JAX-RS resource class field or method parameter using bean validation something like the following: @Size(min = 18, max = 80, message = "Age must be between {min} and {max}.") String age; What is the easiest way to bind the…
siva636
  • 16,109
  • 23
  • 97
  • 135
7
votes
5 answers

Is any reason to put @NotNull annotation on @Id field in Java entity class

I found code in entity class: @Id @NotNull @Column(name = "ID") private Long id; Is @NotNull annotation have value when @Id already set?
gavenkoa
  • 45,285
  • 19
  • 251
  • 303