0

I want to implement login / create account function. I declared a class 'Member' and set fields 'id', 'name', 'password.' I want to use hibernate-validator to validate the fields. Here I have a problem. When you create an account, you need to enter all of the three fields. So I set @NotBlank for all fields. But when you login, you don't input name field. So you always get error message when you try to login. How do I solve this problem?

I have considered adding dummy characters when you login but it is tricky.. Any other solutions?

user3698042
  • 485
  • 1
  • 4
  • 7
  • Check this link. https://howtodoinjava.com/hibernate/hibernate-validator-java-bean-validation/ – Sambit May 14 '19 at 14:05
  • 2
    Possible duplicate of [JSR-303 validation groups define a default group](https://stackoverflow.com/questions/35358447/jsr-303-validation-groups-define-a-default-group) – Nikolai Shevchenko May 14 '19 at 14:15

1 Answers1

1

As mentioned above, condition validation can be obtained by using validation groups.

Our reference documentation gives you all the details for that: https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#chapter-groups .

Groups can be a bit tricky, but considering your simple use case, it should be easy to implement.

Guillaume Smet
  • 9,921
  • 22
  • 29