Is it possible with Envers to have different audit modes for different concrete derived classes with a common a mapped baseclass?

StackOverflow https://stackoverflow.com/questions/23566564

Question

I have two JPA entities with the same fields, which I want to store in different tables. So I have based them on an abstract common mapped base class to avoid doubling code. Now I want one of these table to be audited, and the other one not. But when I set the one class to audited, Envers creates an _AUD table for both of the derived classes. Even setting the other derived class to audit mode NotAudited, its audit table is created. Is there a possibility to configure it as described?

My (simplified) classes:

@MappedBaseClass
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractPrice {
    // some fields and some methods
}

@Entity
@Audited(targetAuditMode=RelationTargetAuditMode.AUDITED)
public class Price extends AbstractPrice {
}

@Entity
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
public class OriginalPrice extends AbstractPrice {
}
Was it helpful?

Solution

The targetAuditMode should be used only for fields which are relations. If you don't want an entity to be audited, simply remove the annotation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top