@Size, using Hibernate Validator, accuses error in value that should pass validation

Asked

Viewed 752 times

1

I have a Java SE application where I can’t use the @size annotation. This annotation is worked out by the org.hibernate.Validator.Size.

There is a user field in the model where I do so:

@Size(min = 1, max = 30) @Column(name = "CAMPO") private String campo;

When trying to save an object it accuses an Invalidstateexception, saying that the value of the String field, which received the value "3216549", should be between 1 and 30 in size. But the value should go through validation.

I tried using @length and did not accuse this error anymore. Does anyone have any idea what might be going on with @size? I read in some places that it is more recommended than @length, for compatibility reasons and wanted to use it.

1 answer

1

Basically both are redundant according to the Documentation of Hibernate:

But note that in the case of Length, the field in the table will have the size set in Max, and this is only valid for Sctring.

On the other hand, you can also set size of other objects as lists for example.

  • I’m using String, so the two would have to work the same way. But Size says the value is invalid (which is wrong) and Length is working correctly. I didn’t understand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.