Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7898161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:21:32+00:00 2026-06-03T08:21:32+00:00

I am using Hibernate Envers to audit some entities. I manually created the associated

  • 0

I am using Hibernate Envers to audit some entities. I manually created the associated audit tables. However, I am having trouble determining what an audit table’s primary key should be. For example, consider a fictional table designed to store customers:

CREATE TABLE CUSTOMER
(
    CUSTOMER_ID   INTEGER,
    CUSTOMER_NAME VARCHAR(100),

    PRIMARY KEY (CUSTOMER_ID)
)

And you create the audit table:

CREATE TABLE CUSTOMER_REVISION
(
    REVISION_ID      INTEGER,
    REVISION_TYPE_ID INTEGER,
    CUSTOMER_ID      INTEGER,
    CUSTOMER_NAME    VARCHAR(100),

    PRIMARY KEY (???)
)

Here were the options I considered:

Primary key: REVISION_ID

This cannot be the primary key because multiple entities of the same class may be modified during the same revision.

Primary key: (REVISION_ID, CUSTOMER_ID)

This seems more likely, but I’m not sure if Envers will insert multiple records per customer per revision.

Primary key: (REVISION_ID, REVISION_TYPE_ID, CUSTOMER_ID)

This seems like overkill, but it may be possible that Envers will insert different types of records (add, modify or delete) per customer per revision.

Primary key: A new column

Perhaps the primary key must simply be another column containing a synthetic primary key.


What is the true primary key of an audit table managed by Hibernate Envers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:21:33+00:00Added an answer on June 3, 2026 at 8:21 am

    Judging by the examples in the documentation, it appears that the primary key in my example would be (REVISION_ID, CUSTOMER_ID). Here is the example in the documentation:

    create table Address (
        id integer generated by default as identity (start with 1),
        flatNumber integer,
        houseNumber integer,
        streetName varchar(255),
        primary key (id)
    );
    
    create table Address_AUD (
        id integer not null,
        REV integer not null,
        flatNumber integer,
        houseNumber integer,
        streetName varchar(255),
        REVTYPE tinyint,
        ***primary key (id, REV)***
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am already using Hibernate Envers to audit entities that are updated by a
I'm using Envers to audit different fields of my entities. The framework works in
I'm using Hibernate Envers for auditing. It works fine. However, I'm try to get
I'm using hibernate to update a record into table. Program is executing fine, but
Using Hibernate 3.6.8.Final and Spring 3.0.5.RELEASE , I'm trying to add some Common DAO
I'm using hibernate, I have a user entity, however I want it to implement
Using hibernate @Any mapping to map multiple entities in the same, I haven't be
I am using hibernate as ORM tool, i want to perform some common stuff
I'm using Hibernate envers to track all changes made to my database objects. These
I am using hibernate. i have read some where about Example.create. what is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.