From the course: Java EE: Bean Validation
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Hibernate constraints implementation
From the course: Java EE: Bean Validation
Hibernate constraints implementation
- Okay, so lets add the credit card constraint to the credit card field in the client bean. So, I'm just going to navigate to the client bean, which, you'll remember, is in the model package, and let's just scroll down to where the credit card is. This is quite a simple constraint, and has only one flag, the Ignore Non-Digit Characters flag, that when set to true, will ignore dashes, spaces, slashes in the credit card number entered. Okay, so let's enter than right now. @CreditCard, okay. And then, we're going to pass into it the flag, and set the flag. In this case, I want the flag to be true, because I want to be able to enter slashes and spaces in my credit card number. Okay, so let's go to the test class. So, as you can see, I have four empty tests. The first test tests whether the number is invalid, the next one tests if the number is valid, then the third test tests to make sure that dashes are acceptable, and then the final one tests to make sure that if it's null, it's not…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.