2 Replies Latest reply on Jul 23, 2009 11:20 AM by bart

    Range validation problems

    bart
      Hi, I'm having trouble validating a byte field like:

        @Column(name = "NUMBER", precision = 2, scale = 0)
        @Range(min = 0, max = 99)
        public Byte getNumber() {
          return this.number;
        }

      when entering a value above 255 the message returned to the user is: value must be a number between 0 and 255
      but when it's below  255 i do get the expected message: value must be a number between 0 and 99!

      Can anyone explain what i'm doing wrong here? Thanks
        • 1. Re: Range validation problems
          acerberus

          My guess is, that hibernate first validates that the value falls into the range of the datatype byte. Since a value above 255 cannot be represented by one byte, hibernate stops the validation process at this point (returning the message that the user should please enter a value that is in the byte range) and your specific more granular validation is never reached.


          This is, however, just a guess.

          • 2. Re: Range validation problems
            bart

            Yes. That's my best guess too. I was just wondering if there is a way around this. I want to override the standard message which is triggered by the 'byte validation' and just use my custom message. Does anyone know a way how to achieve this?
            Thanks,