9

I'm using Hibernate validator to validate my beans.

Actually I have this dependencies on my POM

    <!-- Hibernate validator - Bean validation API Implementation -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.11.Final</version>
    </dependency>

    <!-- Verify validation annotations usage at compile time -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>6.0.11.Final</version>
    </dependency>

    <!-- Unified Expression Language - Spec -->
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>3.0.1-b06</version>
    </dependency>

    <!-- Unified Expression Language - Implementation -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>javax.el</artifactId>
        <version>2.2.6</version>
    </dependency>

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>2.0.1.Final</version>
    </dependency>

And this a pice of my bean

import org.hibernate.annotations.ColumnDefault;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

public class Casa {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Integer id;

    @Column(name="nomcaac") @NotBlank(message = "{casa.nomcaac.null}") @Size(min = 0, max = 300, message = "{casa.nomcaac.size}")
    private String nomcaac;

Now the problem comes when i try to validate my bean, i get this error message

No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'. Check configuration for 'nomcaac'

I can't figure out whats my problem, I think I have the right dependencies according to this page.

Slaw
  • 37,820
  • 8
  • 53
  • 80
Fede Jinich
  • 93
  • 1
  • 1
  • 3
  • Take a look at [their website](http://hibernate.org/validator/releases/6.0/). The `groupId` for Hibernate Validator is `org.hibernate.validator`, not `org.hibernate`. – Slaw Oct 18 '18 at 16:56
  • It's not a big issue as we have a relocation anyway. – Guillaume Smet Oct 18 '18 at 17:04

1 Answers1

15

@NotBlank is new in Bean Validation 2.0 so I suspect you have an old Hibernate Validator version (e.g. 5.x) in your classpath somehow.

You should check your dependency tree with mvn dependency:tree (and your webapp looking for an old jar).

By the way, your javax.el dependencies are incorrect: please refer to https://github.com/hibernate/hibernate-validator/#using-hibernate-validator for the correct one.

Guillaume Smet
  • 9,921
  • 22
  • 29