Questions tagged [hibernate-validator]
Hibernate Validator is the reference implementation for JSR 380 - Bean Validation 2.0
1,169
questions
0
votes
1
answer
16
views
Validator throwing must not be null on optional field
I am out of ideas as to why the following conditional validation always throws a 'department must not be null' exception even though the overwritten isValid method allows it. Other Javax validators on ...
0
votes
0
answers
18
views
JSR380 How to validate String that later will to be converted to BigDecimal? [duplicate]
I am new to JSR380, and I am trying to validate String that will later be converted to BigDecimal. The same variable also needs to accept empty and blank Strings (and convert them to [null]).
Is there ...
1
vote
0
answers
12
views
How to add domain object's ID to validation message?
I have a Spring Boot application, which uses annotations from javax.validation to validate my domain object. Unfortunately, the error message doesn't contain the ID of the domain object. I need the ID ...
0
votes
0
answers
31
views
Conditional Validating Request with SpringBoot
I am using Spring-WebMvc and SpringBoot in constructing a web service, together with spring-boot-starter-validation to simplify the setup.
In the new user requirement, validation needs to be done ...
0
votes
0
answers
52
views
Hibernate Validator: NoSuchMethodException
I'm making a Reddit clone for practice and I added custom validation for unique username. The problem is when I run the app and try to signup I get this exception all the time (when the username is ...
0
votes
1
answer
1k
views
Upgrading from SpringBoot 2.6.6 to 2.6.7 changed behaviour with validation ( javax.validation.ConstraintDeclarationException: HV000151 )
Just recently upgraded from SpringBoot 2.6.6 to 2.6.7, but despite the GAV for hibernate-validator has not changed ( both releases use org.hibernate.validator:hibernate-validator:6.2.3.Final and ...
0
votes
0
answers
14
views
hibernate executableValidator does not work inside the method
I'm trying to implement addNew method parameters validation with this code
public void addNew(@NotNull(message = "FieldManager is Null")
FieldManager ...
0
votes
0
answers
24
views
ConstraintViolationException is not called by ResponseEntityExceptionHandler
I have a Spring Boot RESTful API and I am creating the error system for my API. I want to be able to catch each errors and each validation exceptions in my class that extend ...
0
votes
0
answers
17
views
How to pass javax/jakarta constraints as argument in java
I'm using hibernate-validator and jakarta.validation-api.
I'd like to pass object instance, and constraints to validate it at runtime.
for example:
Validator.validate(Object object, Class<?>... ...
0
votes
0
answers
127
views
Java annotation based validation io.swagger.v3.oas.annotations.media.Schema
Now swagger3(openApi) now is current used. And based on the annotations defined in the library swagger-annoations:2.1.10 and package "io.swagger.v3.oas.annotations", api doc is easily to ...
0
votes
0
answers
25
views
Java Validation not working with @Value.Immutables
I have been at it for 2 days but I can't figure out what I am missing.
My Immutables class looks like:
import org.immutables.value.Value;
import javax.validation.Valid;
import javax.validation....
0
votes
1
answer
30
views
post method not supported in patch method
I want edit entity with validating by hibernate-validator, but when calling the patch method, an error is thrown: post method not supported. How to make @PatchMapping work correctly? I am a beginner ...
0
votes
1
answer
17
views
Why Hibernate Validator doesn't care @Valid but @NotNull only?
I'm trying to check constraints look like this.
class Registration {
@Valid
@NotNull
private User user;
}
class User {
@NotBlank
private String name;
@Max(128)
@Min(0)
...
1
vote
0
answers
34
views
What version of Hibernate validator is suitable for J2ee 8?
I have problem with hibernate validator. When I want to deploy my application on local tomcat, It fails on :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org....
0
votes
0
answers
32
views
Error in hibernate validator while migrating to java 11
I need to migrate my project to Java 11. Its compile right, but on deployment on Tomcat 9 it throws me this exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with ...
0
votes
2
answers
103
views
How to ensure hibernate dependencies are compatible without SpringBoot
I have the following hibernate dependencies
hibernate-core 5.4.3-Final
hibernate-ehcache 5.4.3-Final
hibernate-entitymanager 5.4.3-Final
hibernate-jpamodelgen 5.4.3-Final
hibernate-validator 5.4.3-...
0
votes
0
answers
37
views
Validate 1 field min and max based on another field value using JSR303 Validation
I have 2 fields
Class AgeDTO{
@Min(0)
private int minAge;
@Max(2)
private int maxAge;
private AgeType ageGroup;
}
How to validate minAge and maxAge based on ageGroup values as per below ...
0
votes
1
answer
47
views
with @SpringBootTest (or @WebfluxTest), the errors attribute disappears
I made very simple controller like below.
@PostMapping("/books")
public void create(@Valid @RequestBody BookPayload bookPayload) {
}
@Getter
@Setter
public class BookPayload {
@...
0
votes
1
answer
78
views
A ConstraintValidator referenced by an annotation is never called although it should work
In the debugger, I can see that the annotation somehow works. But the methods initialize(AuthorConstraint) and isValid(Author, ConstraintValidatorContext) of class AuthorConstraintValidator are never ...
0
votes
0
answers
11
views
Spring MVC + Thymelead - Hibernate validator correctly returning errors but not running $Document.ready() function
I have been running into a weird issue. I have a selectbox in a form prepopulated in document.ready(). It is a select2. Everything works fine until I add validators into the solution. If another field ...
0
votes
0
answers
10
views
do these usages of cascaded validation mean same thing?
Looking into documentation regarding @Valid annotation I can't figure out one thing.
Is there any difference between following:
@Valid
List<SomeClass> foo;
List<@Valid SomeClass> foo;
...
0
votes
0
answers
32
views
Bean Validation - lists of the same size
I am using Hibernate Validator implementation of Bean Validation API.
So the question is can I check that some List<...>-typed fields of the class have same size while validating?
0
votes
1
answer
57
views
What is the best way to Validate one field in Java based on another field using hibernate-validator?
I have a class that consists of many fields and these fields have the hibernate-validator Annotations so if the invalid data enters then it can throw the respective message.
Some of the fields are ...
0
votes
1
answer
41
views
How to avoid adding @Valid on each and every inner-class fields during the hibernate-validator?
I am currently developing an application within that I am adding a few validations on an inner class such as @NotNull, @Min, @Max, etc.
To make the validations work I need to add the @Valid on each ...
0
votes
0
answers
56
views
Why @Valid annotation doesn't work with my model in Spring MVC app?
I studying Spring MVC and came to validation.
Here's my build.gradle file.
plugins {
id 'java'
id 'war'
}
group 'org.example'
version '1.0-SNAPSHOT'
def hibernateVersion = '7.0.4.Final'
def ...
-1
votes
1
answer
84
views
How to make validations work with @RequestParam
Given Spring Boot 2.6.3, Hibernate validator 6.2.0.Final, after running the code below:
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation....
1
vote
2
answers
144
views
failed to validate request params in a Spring Boot/Kotlin Coroutines controller
In a SpringBoot/Kotlin Coroutines project, I have a controller class like this.
@RestContollser
@Validated
class PostController(private val posts: PostRepository) {
suspend fun search(@...
0
votes
1
answer
56
views
Using Java validator for SpringBoot properties with @Value annotation
Does anybody know if it's possible to use custom ConstraintValidator for SpringBoot properties with @Value annotation?
Something like this:
@Component
@Validated
public class TestClass {
@...
0
votes
0
answers
21
views
Hibernate validator error response is too short to handle
I use hibernate @NotNull validator .Error response body is too small but it must be large. I get hibernate validator error response like this:
{
"timestamp": "2022-02-17T18:05:11....
1
vote
1
answer
90
views
Spring boot validation constraint call programmatically
I am trying to call a custom validation constraint programmatically, but something isn't working. What am I doing wrong?
MyConstraint.java
@Documented
@Constraint(validatedBy = MyValidator.class)
@...
0
votes
0
answers
112
views
JOIN FETCH expressions cannot be defined with an identification variable
The administrative locations in my country are organized in the following precedence order(largest to smallest):
Country > Region > District > Council > locality.
All entities are well ...
1
vote
2
answers
227
views
How to validate Data in Service Layer?
I've got a problem which I haven't been able to solve.
I am currently building a Rest Api with Spring Boot and I want to validate my User Entity inside of the service layer. I have tried different ...
1
vote
0
answers
63
views
Not able to inject dependency into ConstraintValidator implementation
I have tried several methods to inject dependency into my ConstraintValidator implementation but nothing is working. I have tried almost all stackoverflow threads. I am using Hibernate Validator to ...
1
vote
0
answers
60
views
Is there a way to validate @Column annotation constraints in Kotlin
Given an Entity with the following definition:
@Entity
class myObject (
@Column(name = colName, nullable = false, length = 20)
var myCol: String
) : AbstractJpaPersistableWithId<Int> {
...
1
vote
1
answer
38
views
hibernate validator pojo field with ZoneDateTime field have none normal year
In spring-boot application with rest api and hibernate validator.
Having an api with the following request body, the body can be received as long value or string value.
in case a client sends the date ...
1
vote
1
answer
148
views
Creating a constraint validator for an external, 3rd party annotation
I have an annotation from a third-party library to which I'd like to add a custom validator implementation. Let's call it @Requirement, and define it as follows:
@Target({PACKAGE, TYPE, METHOD, FIELD})...
1
vote
1
answer
99
views
How to specify different locales for each bean validation call
I'm working on a platform that runs Spring Batch jobs which are responsible for retrieving a group of objects from a third party application, performs bean validations and returns any constraint ...
0
votes
1
answer
167
views
Maven dependency org.hibernate.validator 7.0.1.Final with differing dependencies in projects
in two different maven projects, we include the same dependency: hibernate-validator 7.0.1.Final like this:
<dependency>
<groupId>org.hibernate.validator</groupId>...
0
votes
0
answers
91
views
java.lang.NumberFormatException in hibernate validation
i created a custom annotation @Age for check the age like it is integer or not and min and max value
this @Age annotation
@Documented
@Retention(RUNTIME)
@Target(FIELD)
@Constraint(validatedBy = ...
2
votes
2
answers
633
views
How to find deeply layered usages of Log4j
I want to find all usages of log4j prior to the current version (2.15.0).
I tried using maven's "mvn dependency:tree", used several tools (dependency-check, grype (didn't work for me), syft (...
0
votes
0
answers
163
views
how to use annotation to validate LocalDateTime in spring boot
I'm using the @Valid to validate the RequestBod data, see bellow:
Controller MemberController.java
public R<String> addMember(@Valid @RequestBody AddMemberVO memberVO) {
...
}
Model ...
2
votes
2
answers
275
views
Override spring web mvc's default Hibernate Validator
Spring is using the default validator factory provided by hibernate factory. However, I do not want to include an Expression Language dependency.
This answer recommends avoiding using the default ...
0
votes
0
answers
37
views
hibernate validator works in test but not in spring
hibernate validator works well in this unit test:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
...
0
votes
0
answers
39
views
Hibernate constraint validation on groups combination
Here is a simplified structure I have:
// validation groups
public interface Placeholder {};
public interface MainCustomer {};
public interface CoApplicant {};
public class OfferStage {
public ...
1
vote
1
answer
263
views
Hibernate Validator custom constraint not working
I am trying to create a custom contraint with Hibernate Validator.
If I use a standard one such as @Size, it's work well and I got the error message.
However, my custom one is not working and I cannot ...
1
vote
1
answer
150
views
UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.Size' validating type 'java.lang.String'
I am getting this error when running integration tests for an endpoint in Quarkus. I make a POST request passing a valid object as body. Method signature:
@POST
public Response myMethodPost(@Valid ...
0
votes
0
answers
139
views
Unit test Hibernate validation error response in Spring Boot
I am trying to unit test the JSON response Spring Boot sends back to the client when validation of a DTO annotated with @Valid fails. Using Postman, I get a JSON response listing all the validation ...
0
votes
0
answers
46
views
Hibernate Validator without EL interpolation
I would like to turn off Expression Language interpolation in the Hibernate Validator, on version 5.3 but it seems to be available only from version 6.2.
Is it possible somehow? I see that, maybe it ...
1
vote
1
answer
76
views
javax's @Valid annotation usage scenario
Is it possible to use @Valid (javax.validation.Valid) in below scenario?
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.validation.Valid;
import com.incident.tool.model.IncidentModel;...
0
votes
0
answers
207
views
Catching ValidationException instead of a custom Exception in ControllerAdvice
I'm trying to throw an exception inside a custom validator which I built using annotation like that:
ValidExtractionDate annotation:
@Constraint(validatedBy = ExtractionDateValidator.class)
@Target( { ...