Additional JPA annotations - History

In addition to the SCD solution, the JBStrap framework allows you to log history in a separate log file. In this solution, the record history is not stored in a single table along with the data but is stored in a separate table. Log data can be stored along with the data in a single schema or even in a separate schema.

To enable logging for an entity, the entity must have the HistoryCustomizer JPA customizer provided by the framework.

An example for creating an entity with logging:

Settings

Parameterization of the logging module must be done in a properties file. Configuration settings can be included in any properties file loaded in the application. The settings can be made by entering the following keys:

  • hist.schema: This parameter specifies which database schema the log data will be stored in. The program must have permission to write the schema, otherwise, logging will result in an error. The parameter has no value by default, so the logging table is placed in the same schema where the data is stored.
  • hist.table.name.prefix: This parameter specifies the prefix of the logging table name. The logging table name must include log prefixes before the data table name. The default value for this parameter is "HIST_". Accordingly, if the data table to be logged is named TABLE1, the name of the associated log table must be HIST_TABLE1.
  • hist.valid.from: This parameter specifies the name of the field which stores the start of the log record validity. The default value for this parameter is VALID_FROM.
  • hist.valid.to: This parameter specifies the name of the field where the log record validity ends. The default value for this parameter is VALID_TO.
  • hist.deleter.user: This parameter specifies the name of the field in which we want to store the name of the user who deletes the record. This field is only populated when deleted, not when saved. If you want the name of the user who made the change and the name of the user who made the change to be in the same field, set the two parameters to the same value. The default value for this parameter is DELETE_USER_NAME
  • hist.modifier.user: This parameter specifies in which field we want to store the name of the user making the record modification. This field is only populated when a record is created and modified, and not when it is deleted. The default value for this parameter is USER_NAME.
  • hist.domain.uuid.fieldName: This parameter specifies the field which passes the user's uuid to the history. A transient (@Transient) field with the name specified here must be included in the entity. The entity has a @Customizer(HistoryCustomizer.class) annotation. If this parameter is not specified in the property file or there are no transient fields in the entity, then the fields specified in the hist.deleter.user and hist.modifier.user parameters are left empty in the table's associated history entity.

Not all of the parameters need to be specified, it is sufficient to modify those parameters whose default values are not suitable for us.