Hibernate Validator @CPF that can be null

3

I am using Hibernate Validator with the @CPF annotation. It is validating beauty, the problem is that my system may have the invalid CPF field (null) and Hibernate does not accept this. I put the field with @Collumn (nullable = true) but this has no effect on Hibernate.

    
asked by anonymous 02.04.2016 / 07:07

2 answers

1

The problem was that JSF was passing an empty String and not a null value. So I put it in web.xml:

<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-n‌​ame>
    <param-value>true</param-value>
</context-param>
    
05.04.2016 / 19:34
0

I have decided as follows:

@CPF
    @Column(nullable = true)
    private String cpf;

public void setCpf(String cpf) {
        if(cpf != null && cpf.length() == 0) {
            this.cpf = null;
        }
        else {
            this.cpf = cpf;
        }
    }
    
02.06.2017 / 04:05