Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Bean Validation: DecimalMin: Value must be >= this value

If you annotate any number with @DecimalMin annotation, then the number must be higher or equal to the specified minimum.

What are the supported types?
a.   byte,
b.   short,
c.    int,
d.   long,
e.   Byte,
f.     Short,
g.   Integer,
h.   Long,
i.     BigDecimal,
j.     BigInteger,
k.    CharSequence

Note: As per specification double, float is not supported due to rounding errors. Some providers may provide some approximative support

Where can I apply this annotation?
a.   METHOD,
b.   FIELD,
f.     TYPE_USE

Find the below working application.
package com.sample.model;

import javax.validation.constraints.DecimalMin;

public class Employee {

@DecimalMin(value = "500")
private int id;

private String name;

public Employee(int id, String name) { = id; = name;

public int getId() {
return id;

public void setId(int id) { = id;

public String getName() {
return name;

public void setName(String name) { = name;

package com.sample.test;

import java.util.Set;

import javax.validation.*;
import javax.validation.ValidatorFactory;

import com.sample.model.Employee;

public class Test {
private static ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
private static Validator validator = validatorFactory.getValidator();

private static void validateBean(Employee emp) {
SetConstraintViolationEmployee>> validationErrors = validator.validate(emp);

if (validationErrors.size() == 0) {
System.out.println("No validation errors....");

for (ConstraintViolationEmployee> violation : validationErrors) {
System.out.println(violation.getPropertyPath() + "," + violation.getMessage());

public static void main(String args

This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Bean Validation: DecimalMin: Value must be >= this value


Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription