Search code examples
hibernate-envers

Hibernate Envers rev column data type is Integer


I am using Hibernate Envers in my application to store audit trail data, all audit related information are storing in *_AUD table correctly. However, the data type of rev column in all _AUD table is Integer data type. I am expecting a big int data type because the maximum range of integer data type is 2147483647. Is there a way to change the data type to big int?


Solution

  • By default, the Envers implementation uses an Integer data type for the REV column.

    In order to leverage a Long data type, you'll need to supply a custom revision entity with the appropriate annotations. Below is an example that will replace the existing default implementation while using a BIGINT compatible REV column.

    @Entity
    @RevisionEntity
    public class CustomRevisionEntity implements Serializable {
      @Id
      @GeneratedValue
      @RevisionNumber
      private Long rev;
      @RevisionTimestamp
      private Long timestamp;
      /* provide getter/setters */
    }
    

    NOTE: All audit tables will make their REV column's data type match that of the data type you use in the revision entity class.

    There is an open JIRA HHH-6615 to migrate the default implementations to use Long instead of Integer based revisions; however, it does require that we consider upgrade paths as a implementation detail of that issue to account for existing users.

    Until then, using a custom revision entity for new implementations is a workaround.