Hibernate Envers does not persist foreign key in audit table
15:06 04 Nov 2025

I'm using Hibernate Envers to audit a @OneToMany relationship between two entities: ParentEntity and ChildEntity.

I am not using @ManyToOne on the ChildEntity side. Instead, I store the foreign key directly as an Integer parentId.

In the main child_entity table, the parent_id value is correctly persisted. However, in the audit table (child_entity_aud), this field is always null, even though it is marked as @Audited.

Using @ManyToOne is not an option in my case — I only want to store the raw ID without joining or loading the full parent entity.

I also tried @AuditJoinTable, but as far as I understand, it only applies to collections and many-to-many relations.

How can I make Envers persist a foreign key (parentId) to the audit table without using @ManyToOne?

@Entity
@Audited
@Table(name = "parent_entity")
public class ParentEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "parent_id") // FK in child
    private List children = new ArrayList<>();
}

@Entity
@Audited
@Table(name = "child_entity")
public class ChildEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    // Just a raw FK, no @ManyToOne
    @Column(name = "parent_id")
    @Audited
    private Integer parentId;

    private String data;
}

Observed Behavior:

child_entity.parent_id is saved correctly

child_entity_aud.parent_id is always null

How can I make this work without introducing a @ManyToOne association?

java hibernate hibernate-envers