java - JPA/Hibernate: Allow Integer to be null or in a set range of numbers? -


i want have integer field field in table should allowed take 1 of following values:

null 0 1 2 

is possible accomplish using jpa or hibernate annotations? i've tried @min @max , @range didn't seem work.

to more precise: want error thrown when insert or update command executed sets field different null, 0, 1 or 2.

@entity public class counter {      @id     private int id;      @notnull     private string name;      @null     @min(0)     @max(2)     private int count;      ..     .. } 

for validation need validate this

counter counter = new counter(); counter.setname("msg"); counter.setcount(3);  validatorfactory factory = validation.builddefaultvalidatorfactory(); validator validator = factory.getvalidator(); set<constraintviolation<counter>> constraints = validator     .validate(counter); (constraintviolation<counter> constraint : constraints) {     system.out.println(constraint.getpropertypath() + "  "     + constraint.getmessage()); 

i think should work in case. not jpa/hibernate validation, bean validation.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -