Configuration for Oracle

Envers won't work with Oracle using the default settings, as Oracle doesn't accept fields and tables that have names starting with an underscore (_). It is easy however, to configure those names.

First of all, you'll need to change the name of the revision entity (it contains information about the date of the revision and possibly more). You can do that by adding a very simple entity (see "Logging data for revisions" for more information):

package org.jboss.envers.example;

import org.jboss.envers.RevisionNumber;
import org.jboss.envers.RevisionTimestamp;
import org.jboss.envers.RevisionEntity;

import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.Entity;

@Entity
@RevisionEntity
@Table("REV_ENT")              // any name you like
public class ExampleRevEntity {
    @Id
    @GeneratedValue            // any auto-generated value is ok
    @RevisionNumber
    @Column("ID")
    private Integer id;        // can also be a Long

    @RevisionTimestamp
    @Column("TMSTMP")
    private Long timestamp;

    // Getters, setters, equals, hashCode ...
}

Secondly, you'll need to change the names of the fields that are added to the version entities. You will need to add the following two bottom properites to your persistence.xml file: (see "Configuration" for more information):

   <persistence-unit ...>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>...</class>
        <properties>
            <property name="hibernate.dialect" ... />
            <!-- other hibernate properties -->
 
            <!-- Envers listeners -->
            <property name="hibernate.ejb.event.post-insert" 
	              value="org.jboss.envers.event.VersionsEventListener" />
            <property name="hibernate.ejb.event.post-update" 
	              value="org.jboss.envers.event.VersionsEventListener" />
            <property name="hibernate.ejb.event.post-delete" 
	              value="org.jboss.envers.event.VersionsEventListener" />
		
            <!-- Envers properties - changing the name of the generated fields -->
	    <!-- Again, the values of these are up to you -->
            <property name="org.jboss.envers.revisionTypeFieldName" value="VER_REV_TYPE" />
            <property name="org.jboss.envers.revisionFieldName" value="VER_REV" />
            <!-- other envers properties -->
        </properties>
    </persistence-unit>