jakartaee / validation

Jakarta Validation
http://beanvalidation.org
Apache License 2.0
127 stars 54 forks source link

please create a validation for unique value for a column in mentions table #193

Closed imhayatunnabi closed 10 months ago

imhayatunnabi commented 10 months ago

please create a validation for unique value for a column in mentions table

like @UniqueColumnValue(table = ""tableName", columnName = "columnName")

in request dto

mswatosh commented 10 months ago

Hi @imhayatunnabi, the list of built-in constraints in the specification is intentionally kept very small and broadly usable. This constraint idea is too specific for the validation spec, and I'm not sure if there are any implementations which support DB constraints. I would recommend looking into creating a custom constraint, there is a guide here: https://docs.jboss.org/hibernate/validator/8.0/reference/en-US/html_single/#validator-customconstraints

gsmet commented 10 months ago

Yeah, database constraints should be handled at the database level. It's the only way to get them right, transaction-wise.

We intentionally stayed away of implementing this type of things in Jakarta Validation as it can be both suboptimal and incorrect.