The NoSQL databases are famous because they are schemaless. That means a developer does need to care about a pre-defined type as it does on a relational database; thus, it makes it easier for developers to create an application. However, it has a considerable price once there is no structure that is not trivial to validate it on the database. To ensure integrity, the solution should work on the server side. There is a specification and framework in the Java world that is smoother and annotation-driven: bean validation. This post will cover how to integrate bean validation in a NoSQL database.
Bean Validation, JSR 380, is a specification which ensures that the properties of a Class match specific criteria, using annotations such as @NotNull
, @Min
, and @Max
, also create its annotation and validation. It is worth noting bean validation does not, necessarily, mean an anemic model; in other words, a developer can use it with good practices to get data integrity.