Additional JPA annotations - Audit

In the JBStrap framework, you can audit record operations, that is, you can query which user performed an operation on a record and when. This can be done by placing one or more of the following annotations in the entity field where you want to store auditing information.

An example for an entity with auditing annotations:

Creator

This annotation can be placed in the entity field where you want to store the name of the user who created the record. A prerequisite for annotations to work is that when performing a database operation (when creating a record) you have to pass the client instance initiating the operation (the logged-in client) to the operation itself. This is true for JPA DAO API as well as DataDescriptors .

In the above example, the creator_username field of the table in the database will include the name of the user who created the record. This information is not overwritten even if the record is modified.

Saving a record to an entity: the annotation will fill in the creator user name:

After saving, the value of the creatorUserName attribute in the record will be populated with the username of the user logged on to the client client.

CreatorTimestamp

This annotation can be placed in the entity field where you want to store the record creation timestamp. A prerequisite for annotations to work is that when performing a database operation (when creating a record) you have to pass the client instance initiating the operation (the logged-in client) to the operation itself. This is true for JPA DAO API as well as DataDescriptors .

In the example above, the field named created in the database table will include the exact time the record was created. This information is not overwritten even if the record is modified.

We save a record to the above entity, where the annotation will fill in the time the record was created:

After saving, the value of the created attribute in the record will be populated with the time the record was created.

Modifier

This annotation can be placed in the entity field where we want to store the name of the user who performed a record modification. A prerequisite for annotations to work is that when performing a database operation (when creating a record) you have to pass the client instance initiating the operation (the logged-in client) to the operation itself. This is true for JPA DAO API as well as DataDescriptors .

The value of the annotated field is filled in only when it is modified, not when a new record is created. Any save operation in which the record's unique identifier is populated is a modification.

In the above example, the name of the user who modified the record will be entered into the last_modifier_username field of the database table. This happens upon every modification: the user name associated with the last modification is saved.

Modifying a record in the above entity where the annotation will save the name of the user who performed the modification:

After saving, the value of the modifierUserName attribute in the record will be populated with the username of the user logged on to the client client.

ModifierTimestamp

This annotation can be placed in the entity field where you want to store the record modification date. A prerequisite for annotations to work is that when performing a database operation (when creating a record) you have to pass the client instance initiating the operation (the logged-in client) to the operation itself. This is true for JPA DAO API as well as DataDescriptors . The value of the annotated field is filled in only when it is modified and not when a new record is created. Any save operation in which the record's unique identifier is populated is a modification.

In the above example, the last_modify field in the database table will be updated with the date of the modification. This happens every time you change the field, therefore the field will always show the date the record was last modified.

In the above entity, we modify a record where the annotation will fill the date of the modification:

After saving, the value of the modify attribute in the record will be filled with the time of the modification.