Articles

Checking rows integrity by adding a signature column to tables

  Introduction In this tutorial I explain how to add extra checks for data integrity on the row level, by adding a signature column which will contain a signature for all the other row columns. For that purpose I will use spring framework (spring -boot) and hibernate. GitHub repository A full and working example is available on this  GitHub repository Use case If you store some sensitive data you might want to ensure that no one else besides your application has changed it; or else you consider that your data is no longer valid. Let's take this as a starting point for what's next. Assuming that we have a  Payment  entity that having following fields: id  a  Long  represents the id of the row amount  a  BigDecimal  represents the amount paid by the customer date  a  ZonedDateTime  for the payment date and time address  a  String  for the invoicing address To those fields we will add a signature field. signatu...

Manipulating Entity ID before it gets inserted

Introduction In this tutorial I will explain how to manipulate an entity  ID  even before it gets inserted into the database table. For that purpose I will use spring framework (spring -boot) and hibernate. Use case Assume that you have a column that you need to update based on the row  ID ; however the entity is not created yet; so the  ID  doesn't exist yet. A basic use case consists of creating an entity  Odd , that has besides its  ID  a property called  isOdd  to store whether the ID is odd or even. GitHub repository A working spring-boot project is available on this  GitHub repository Let's get hands dirty Use a sequence generator for the ID The first step is delegating the  ID  generation to Hibernate by using a sequence generation strategy and by defining a sequence generator for it, that way the  ID  will be generated and included in the insert query; that hibernate will send to the RDBMS for persistence...