

Somehow Hibernate Envers needs to know which user has added, modified or deleted data. package de. import import import javax.persistence.* import java.io.Serializable import import public class CustomRevisionEntity implements Serializable Determining the Current Auditor
#Java annotations database schema full
See LICENSE file in the project root for full license information. We need to add a MappedSuperclass annotation. The framework needs to know, that the class provides database mappings. This class simply provides the Revision Number (maps to revision_number in the database) and the Revision Timestamp I want to provide generic methods for working with Hibernate Envers, so I will define Hibernate Envers needs a Revision Entity, which maps to the revision table in the database.


The interface for accessing the auditioned customer table, and getting the audition and versioned data.The Customer History, which basically maps to the audited Customer table ( sample.customer_aud).This exception is thrown, if no Username was given to the application. The application needs to be given a Username for being able to audit data.This class is necessary to provide the information, which user added / modified / deleted data.This class provides a utility method to turn the untyped AuditQuery result list into a strongly typed list of AuditQueryResult. An AuditQuery returns a List of untyped Object.This class provides methods to convert between the untyped Object and turns it into a strongly typed AuditQueryResult.

The AuditQuery results of Hibernate Envers are simply Object, which makes it hard to work with in the application.It holds the audited entity data, the revision and the revision type. A container for the Results of an Audit Query.The Revision Entity for the application, which defines the mapping to the sample.revinfo table.The base class for Revision Entities with the revision number and revision timestamp.It's useful to take a look at the project structure first: IF NOT EXISTS ( SELECT 0 FROM pg_class where relname = 'hibernate_sequence' ) THEN CREATE SEQUENCE hibernate_sequence INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 END IF The Spring Boot Application Project Structure This sequence can be created with the CREATE SEQUENCE SQL Statement. Hibernate Envers needs a SEQUENCE named hibernate_sequence to increase the revision numberįor versioned entities. revinfo ( revision_number integer NOT NULL, revision_timestamp bigint, CONSTRAINT revinfo_pkey PRIMARY KEY ( revision_number ) ) END IF Sequences tables WHERE table_schema = 'sample' AND table_name = 'revinfo' ) THEN CREATE TABLE sample. customer_aud ( customer_id SERIAL, first_name VARCHAR ( 255 ) NOT NULL, last_name VARCHAR ( 255 ) NOT NULL, created_by VARCHAR ( 255 ), created_at TIMESTAMP, last_modified_by VARCHAR ( 255 ), last_modified_at TIMESTAMP, rev integer NOT NULL, revtype smallint ) END IF IF NOT EXISTS ( SELECT 1 FROM information_schema. tables WHERE table_schema = 'sample' AND table_name = 'customer_aud' ) THEN CREATE TABLE sample.
#Java annotations database schema serial
customer ( customer_id SERIAL PRIMARY KEY, first_name VARCHAR ( 255 ) NOT NULL, last_name VARCHAR ( 255 ) NOT NULL, created_by VARCHAR ( 255 ), created_at TIMESTAMP, last_modified_by VARCHAR ( 255 ), last_modified_at TIMESTAMP ) END IF IF NOT EXISTS ( SELECT 1 FROM information_schema. tables WHERE table_schema = 'sample' AND table_name = 'customer' ) THEN CREATE TABLE sample. IF NOT EXISTS ( SELECT 1 FROM information_schema.
