I have used @Pattern
to validate text input for a long time in my project and never had an issue. All of a sudden I'm getting the following error:
jakarta.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'jakarta.validation.constraints.Pattern' validating type 'com.helpmesaythis.hmst3.profile.promo.model.entity.DiscountPromoCode'. Check configuration for 'discountPromoCode'
There are two strange things at play:
There are other classes using it without an issue and I haven't even touched this problematic class in a long time (it has always worked).
I have tried commenting out and even deleting it entirely from the class, yet the error still appears. How is it causing an issue when it doesn't even exist?
import com.helpmesaythis.hmst3.profile.partner.model.entity.Partner;
import jakarta.persistence.*;
import jakarta.validation.constraints.Pattern;
@Entity
@Table(name = "discount_promo_code")
public class DiscountPromoCode {
...
@Size(min = 4, max = 20, message = "Promo Code must be between 4-20 characters")
@Pattern(regexp = "[A-Za-z0-9]+$", message = "Promo Code can contain only letters and numbers")
@Column(name = "promo_code")
private String promoCode;
...
}
I have made sure that all dependencies are up to date. My Spring Boot is up to date.
Again - the @Pattern
annotation works everywhere else, yet I get the same error message even after it has been deleted from the problematic class.
When I include spring.jpa.properties.javax.persistence.validation.mode=none
everything works as it should.
Any ideas?
As andrewJames pointed out in the comments, the error was coming from the field discountPromoCode
and not the class DiscountPromoCode
. The error itself was because I was using @Pattern
to validate a field that was not a String.