Entity and pattern validation vs DB constraint

Posted by Joerg on Programmers See other posts from Programmers or by Joerg
Published on 2012-06-28T16:32:20Z Indexed on 2012/06/28 21:24 UTC
Read the original article Hit count: 194

Filed under:
|
|
|

When it comes to performance: What is the better way to validate the user input?

If you think about a phone number and you only want numbers in the database, but it could begin with a 0, so you will use varchar:

Is it better to check it via the entity model like this:

 @Size(min = 10, max = 12)
 @Digits(fraction = 0, integer = 12)
 @Column(name = "phone_number")
 private String phoneNumber;

Or is it better to use on the database side a CHECK (and no checking in the entity model) for the same feature?

© Programmers or respective owner

Related posts about java

Related posts about mysql