difference between @size(max = value ) and @min(value) @max(value)

JOHND picture JOHND · Jun 25, 2012 · Viewed 114.7k times · Source

I want ot do some domain validation

in my object i am having one integer ,

now my question is if i write

@Min(SEQ_MIN_VALUE)
@Max(SEQ_MAX_VALUE)
private Integer sequence;

and

 @Size(min = 1, max = NAME_MAX_LENGTH)
 private Integer sequence;

If it's integer which one is proper for domain validation.

can anybody explain me what is the difference between them ?

Thanks.

Answer

Sunil Chavan picture Sunil Chavan · Jun 25, 2012

@Min and @Max are used for validating numeric fields which could be String(representing number), int, short, byte etc and their respective primitive wrappers.

@Size is used to check the length constraints on the fields.

As per documentation @Size supports String, Collection, Map and arrays while @Min and @Max supports primitives and their wrappers. See the documentation.