I was interested lately. Suppose we make a webapp with JSF + Spring + JPA / Hibernate (or some other technology is good), and we can say that we have a "user" entity. We want the User to have a unique login. If we want to do this, we can put @UniqueConstraint in the "Input" column, but still, our application must check during user registration whether the user’s input is valid (unique) or not, without this and only with a DB restriction we just get a mistake. Does it make me think that DB constraints are really necessary / useful? The only thing I can think of when they will give us any advantages is when someone tries to hack us (but I think that our application should be proof of SQL injection in any case) or we try to manually change the contents of the database data (which should not really happen). In fact, now that I am thinking about it, are there DB limitations in general necessary / good practices? Like string length etc.
database database-design constraints unique-constraint
Mateusz dymczyk
source share